Zend framerwork DB DDL update

人走茶凉 提交于 2019-12-13 04:02:01

问题


I am new to zend and i want to use the DB module for an application.

I have this code

$DB = new Zend\Db\Adapter\Adapter(array(
    'driver' => 'Mysqli',
    'database' => 'database',
    'username' => 'user',
    'password' => 'pass'
));
use Zend\Db\Sql\Ddl;
use Zend\Db\Sql\Ddl\Column;
use Zend\Db\Sql\Ddl\Constraint;
$table = new Ddl\CreateTable('table');
$table->setTable('table');
$table->addColumn(new Column\Integer('id',false,NULL,array('autoincrement'=>true)));
$table->addColumn(new Column\Varchar('name', 255));
$table->addConstraint(new Constraint\PrimaryKey('id'));

Table is not created, there is an update function? i can't find it.


回答1:


You created DDL statement object and Adapter, but you haven't executed it. You will need 1 more object for execution and that's SQL instance. In your case it could look like this:

use Zend\Db\Sql\Sql;

// your code

$sql = new Sql($DB);

$DB->query(
    $sql->getSqlStringForSqlObject($table),
    $DB::QUERY_MODE_EXECUTE
);

More at Zend Framework's docs



来源:https://stackoverflow.com/questions/21955562/zend-framerwork-db-ddl-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!