Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top