src/Charcoal/Source/DatabaseSource.php
public function createTable()
    {
        if ($this->tableExists() === true) {
            return true;
        }

        $dbh      = $this->db();
        $driver   = $dbh->getAttribute(PDO::ATTR_DRIVER_NAME);
        $model    = $this->model();
        $metadata = $model->metadata();

        $table   = $this->table();
        $fields  = $this->getModelFields($model);
        $columns = [];
        foreach ($fields as $field) {
            $columns[] = $field->sql();
        }

        $query  = 'CREATE TABLE  `'.$table.'` ('."\n";
        $query .= implode(',', $columns);

        $key = $model->key();
        if ($key) {
            $query .= ', PRIMARY KEY (`'.$key.'`) '."\n";
        }

        /** @todo Add indexes for all defined list constraints (yea... tough job...) */
        if ($driver === self::MYSQL_DRIVER_NAME) {
            $engine = 'InnoDB';
            $query .= ') ENGINE='.$engine.' DEFAULT CHARSET=utf8 COMMENT="'.addslashes($metadata['name']).'";';
        } else {
            $query .= ');';
        }

        $this->logger->debug($query);
        $dbh->query($query);

        return true;
    }
public function createTable()
    {
        if ($this->tableExists() === true) {
            return true;
        }

        $dbh      = $this->db();
        $driver   = $dbh->getAttribute(PDO::ATTR_DRIVER_NAME);
        $model    = $this->model();
        $metadata = $model->metadata();

        $table   = $this->table();
        $fields  = $this->getModelFields($model);
        $columns = [];
        foreach ($fields as $field) {
            $columns[] = $field->sql();
        }

        $query  = 'CREATE TABLE  `'.$table.'` ('."\n";
        $query .= implode(',', $columns);

        $key = $model->key();
        if ($key) {
            $query .= ', PRIMARY KEY (`'.$key.'`) '."\n";
        }

        /** @todo Add indexes for all defined list constraints (yea... tough job...) */
        if ($driver === self::MYSQL_DRIVER_NAME) {
            $engine = 'InnoDB';
            $query .= ') ENGINE='.$engine.' DEFAULT CHARSET=utf8 COMMENT="'.addslashes($metadata['name']).'";';
        } else {
            $query .= ');';
        }

        $this->logger->debug($query);
        $dbh->query($query);

        return true;
    }
public function createTable ( ) { if ( $ this -> tableExists ( ) === true ) { return true ; } $ dbh = $ this -> db ( ) ; $ driver = $ dbh -> getAttribute ( PDO :: ATTR_DRIVER_NAME ) ; $ model = $ this -> model ( ) ; $ metadata = $ model -> metadata ( ) ; $ table = $ this -> table ( ) ; $ fields = $ this -> getModelFields ( $ model ) ; $ columns = [ ] ; foreach ( $ fields as $ field ) { $ columns [ ] = $ field -> sql ( ) ; } $ query = 'CREATE TABLE  `' . $ table . '` (' . "\n" ; $ query .= implode ( ',' , $ columns ) ; $ key = $ model -> key ( ) ; if ( $ key ) { $ query .= ', PRIMARY KEY (`' . $ key . '`) ' . "\n" ; } /** @todo Add indexes for all defined list constraints (yea... tough job...) */ if ( $ driver === self :: MYSQL_DRIVER_NAME ) { $ engine = 'InnoDB' ; $ query .= ') ENGINE=' . $ engine . ' DEFAULT CHARSET=utf8 COMMENT="' . addslashes ( $ metadata [ 'name' ] ) . '";' ; } else { $ query .= ');' ; } $ this -> logger -> debug ( $ query ) ; $ dbh -> query ( $ query ) ; return true ; }
Create a table from a model's metadata.

@return boolean TRUE if the table was created, otherwise FALSE.
Create a table from a model s metadata .