Zendframework 2 postgresql 更新 "not"
Zendframework 2 postgresql update with "not"
是否可以使用 tableGateway 将以下 sql 查询传递给数据库,如果可以,这样的命令会是什么样子?
UPDATE table_data SET active = not active where table_data.id = 12;
你需要使用一个Zend\Db\Sql\Expression
,这个class告诉Zend\Db
你知道你在做什么,并且传递给这个[=15=的字符串的内容] 不应转换,而是按原样使用。
// 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
);
是否可以使用 tableGateway 将以下 sql 查询传递给数据库,如果可以,这样的命令会是什么样子?
UPDATE table_data SET active = not active where table_data.id = 12;
你需要使用一个Zend\Db\Sql\Expression
,这个class告诉Zend\Db
你知道你在做什么,并且传递给这个[=15=的字符串的内容] 不应转换,而是按原样使用。
// 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
);