Ejemplo n.º 1
0
 /**
  * Executes the query and returns DataSet.
  * 
  * @return \array[][]
  */
 public function GetData()
 {
     $commands = DBCommand::GetCommandArray($this->Command);
     $result = array();
     foreach ($commands as $command) {
         // prepare
         $stmt = $this->PrepareQuery($command->CommandText, $command->Parameters);
         // execute
         if ($stmt->execute() === FALSE) {
             $this->ThrowException($stmt);
         } else {
             if (!($get_result = $stmt->get_result()) || ($get_result = $get_result->fetch_all(MYSQLI_ASSOC)) === FALSE) {
                 $this->ThrowException($stmt);
             } else {
                 $result[] = $get_result;
             }
         }
         // close
         $stmt->close();
     }
     if ($this->ConnectionMode === ConnectionMode::Auto) {
         $this->Disconnect();
     }
     return $result;
 }
 /**
  * @static
  */
 function RemoveByID($classname, $id)
 {
     eval('$tmp = new ' . $classname . '();');
     $tmp->_db_Init();
     $cmd = new DBCommand("DELETE FROM @_db_table WHERE id=@id");
     $cmd->Add('@_db_table', DB_TableName, $tmp->_db_table);
     $cmd->Add('@id', DB_Int, $id);
     DB::Execute($cmd);
 }
 function GetTableColumns($table)
 {
     static $tables_columns = array();
     if (!array_key_exists($table, $tables_columns)) {
         $cmd = new DBCommand("SHOW COLUMNS FROM @tbname");
         $cmd->Add('@tbname', DB_TableName, $table);
         $res = DB::GetAll($cmd);
         $fields = array();
         foreach ($res as $row) {
             $type = $row['Type'];
             if (strpos($type, '(') !== false) {
                 $typename = substr($type, 0, strpos($type, '('));
                 $type = substr($type, strpos($type, '(') + 1);
                 if (strpos($type, ')') !== false) {
                     $size = intval(substr($type, 0, strpos($type, ')')));
                 } else {
                     $size = 255;
                 }
             } else {
                 $typename = $type;
                 $size = 255;
             }
             switch ($typename) {
                 case 'varchar':
                     $tp = DB_String;
                     break;
                 case 'tinyint':
                     $tp = DB_Int;
                     break;
                 case 'text':
                     $tp = DB_Blob;
                     break;
                 case 'date':
                     $tp = DB_Date;
                     break;
                 case 'smallint':
                     $tp = DB_Int;
                     break;
                 case 'mediumint':
                     $tp = DB_Int;
                     break;
                 case 'int':
                     $tp = DB_Int;
                     break;
                 case 'bigint':
                     $tp = DB_Int;
                     break;
                 case 'float':
                     $tp = DB_Float;
                     break;
                 case 'double':
                     $tp = DB_Float;
                     break;
                 case 'decimal':
                     $tp = DB_Float;
                     break;
                 case 'datetime':
                     $tp = DB_DateTime;
                     break;
                 case 'timestamp':
                     StrikeError('DB::GetTableColumns : TODO: check mysql manual for \'timestamp\'');
                     break;
                 case 'time':
                     StrikeError('DB::GetTableColumns : TODO: check mysql manual for \'time\'');
                     break;
                 case 'year':
                     StrikeError('DB::GetTableColumns : TODO: check mysql manual for \'year\'');
                     break;
                 case 'char':
                     $tp = DB_String;
                     break;
                 case 'tinyblob':
                     $tp = DB_Blob;
                     break;
                 case 'tinytext':
                     $tp = DB_Blob;
                     break;
                 case 'blob':
                     $tp = DB_Blob;
                     break;
                 case 'mediumblob':
                     $tp = DB_Blob;
                     break;
                 case 'mediumtext':
                     $tp = DB_Blob;
                     break;
                 case 'longblob':
                     $tp = DB_Blob;
                     break;
                 case 'longtext':
                     $tp = DB_Blob;
                     break;
                 case 'enum':
                     StrikeError('DB::GetTableColumns : unsupported type \'enum\'');
                     break;
                 case 'set':
                     StrikeError('DB::GetTableColumns : TODO: check mysql manual for \'set\'');
                     break;
                 default:
                     StrikeError('DB::GetTableColumns : unknown field type \'' . $typename . '\'');
             }
             $fields[$row['Field']] = array('t' => $tp, 's' => $size);
         }
         $tables_columns[$table] = $fields;
     }
     return $tables_columns[$table];
 }
Ejemplo n.º 4
0
//load router configuration
$router_conf = (require_once RA_CONFIG_PATH . '/router.php');
$ROUTER = new UserRouter();
//load slice routes
foreach (glob(RA_SLICES_PATH . "/*/config/router.php") as $router) {
    include_once $router;
}
try {
    $current_route = $ROUTER->match($current_uri);
} catch (Ra_RouterException $e) {
    dispatch_error($e, 404);
}
//disable magic quotes
include_once RA_SYSTEM_CORE_PATH . '/magic_quotes.php';
//transform upload format
include_once RA_SYSTEM_CORE_PATH . '/upload_transform.php';
//load database
require_once RA_SYSTEM_DATABASE_PATH . '/ActiveRecord.php';
$db_conf = (include RA_CONFIG_PATH . '/db.php');
FieldAct::set_upload_path(RA_UPLOAD_PATH . '/');
DBCommand::configure($db_conf->host, $db_conf->user, $db_conf->password, $db_conf->database);
//if your submodules needs to do something, this is the time!
foreach (glob(RA_SLICES_PATH . "/*/config/setup.php") as $setup) {
    include_once $setup;
}
//run!
try {
    Ra_Controller::run($current_route);
} catch (Exception $e) {
    dispatch_error($e);
}