Zend Framerwork DB DDL更新 [英] Zend framerwork DB DDL update

查看:91
本文介绍了Zend Framerwork DB DDL更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是zend的新手,我想为应用程序使用DB模块。

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

我有此代码

$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.

推荐答案

您创建了 DDL语句对象 Adapter ,但您尚未执行它。您还需要1个对象才能执行,该对象是 SQL 实例。在您的情况下,它看起来可能像这样:

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
);

更多内容请参见 Zend Framework的文档

这篇关于Zend Framerwork DB DDL更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆