[英]Zend framerwork DB DDL update
I am new to zend and i want to use the DB module for an application. 我是zend的新手,我想为应用程序使用DB模块。
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.
我找不到它。
You created DDL statement object and Adapter , but you haven't executed it. 您创建了DDL语句对象和Adapter ,但是尚未执行它。 You will need 1 more object for execution and that's SQL instance.
您将需要再执行1个对象,这就是SQL实例。 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 Zend Framework文档中的更多内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.