0

tableGateway を使用して次の SQL クエリをデータベースに渡すことは可能ですか?

UPDATE table_data SET active = not active where table_data.id = 12;
4

1 に答える 1

0

を使用する必要がありますZend\Db\Sql\Expression。このクラスはZend\Db、自分が何をしているのかを知っていること、およびこのクラスに渡された文字列の内容を変換するべきではなく、そのまま使用するべきであることを示しています。

// build the table gateway object
$adapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
$tableIdentifier = new TableIdentifier('table_data', 'public');
$tableGateway = new TableGateway($tableIdentifier, $adapter);

// create the filter
$where = new \Zend\Db\Sql\Where();
$where->equalTo('id', '12');

// update table
$tableGateway->update(
    ['active' => new \Zend\Db\Sql\Expression('not active')], 
    $where
);
于 2015-05-07T12:50:07.320 に答える