Solar_Sql_Adapter::createTable PHP Method

createTable() public method

The $cols parameter should be in this format ... {{code: php $cols = array( 'col_1' => array( 'type' => (string) bool, char, int, ... 'size' => (int) total length for char|varchar|numeric 'scope' => (int) decimal places for numeric 'default' => (bool) the default value, if any 'require' => (bool) is the value required to be NOT NULL? 'primary' => (bool) is this a primary key column? 'autoinc' => (bool) is this an auto-increment column? ), 'col_2' => array(...) ); }} For available field types, see Solar_Sql_Adapter::$_native.
public createTable ( string $table, array $cols ) : string
$table string The name of the table to create.
$cols array Array of columns to create.
return string An SQL string.
    public function createTable($table, $cols)
    {
        $this->_cache->deleteAll();
        $stmt = $this->_sqlCreateTable($table, $cols);
        $this->query($stmt);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * 
  * Creates the table and indexes in the database using $this->_table_cols
  * and $this->_index.
  * 
  * @return void
  * 
  */
 protected function _createTableAndIndexes()
 {
     /**
      * Create the table.
      */
     $this->_sql->createTable($this->_table_name, $this->_table_cols);
     /**
      * Create the indexes.
      */
     foreach ($this->_index as $name => $info) {
         try {
             // create this index
             $this->_sql->createIndex($this->_table_name, $info['name'], $info['type'] == 'unique', $info['cols']);
         } catch (Exception $e) {
             // cancel the whole deal.
             $this->_sql->dropTable($this->_table_name);
             throw $e;
         }
     }
 }
All Usage Examples Of Solar_Sql_Adapter::createTable