postgresql 在 zf2 table 网关中返回
postgresql RETURNING in zf2 table gateway
如何在通过 table 网关插入时添加 RETURNING 子句?
INSERT INTO users (name, age) VALUES ('Liszt', 10) RETURNING id;
$dataArray = array('name'=> 'Liszt','age' => 10);
$this->tableGateway->insert($dataArray);
$userId = $this->tableGateway->lastInsertValue;
另一种方法是:
$userId = $this->tableGateway->getLastInsertValue();
如果你想在插入到 tablegateway 时在 postgresql 中获取最后的插入 ID,你必须使用 SequenceFeature。
$myTable = new TableGateway('table_name', $dbAdapter, new Feature\SequenceFeature('primary_key', 'sequence_name'));
$id = $myTable->insert(array(/*your data*/));
如何在通过 table 网关插入时添加 RETURNING 子句?
INSERT INTO users (name, age) VALUES ('Liszt', 10) RETURNING id;
$dataArray = array('name'=> 'Liszt','age' => 10);
$this->tableGateway->insert($dataArray);
$userId = $this->tableGateway->lastInsertValue;
另一种方法是:
$userId = $this->tableGateway->getLastInsertValue();
如果你想在插入到 tablegateway 时在 postgresql 中获取最后的插入 ID,你必须使用 SequenceFeature。
$myTable = new TableGateway('table_name', $dbAdapter, new Feature\SequenceFeature('primary_key', 'sequence_name'));
$id = $myTable->insert(array(/*your data*/));