本文整理汇总了PHP中Zend\Db\TableGateway\TableGateway::getLastInsertValue方法的典型用法代码示例。如果您正苦于以下问题:PHP TableGateway::getLastInsertValue方法的具体用法?PHP TableGateway::getLastInsertValue怎么用?PHP TableGateway::getLastInsertValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Db\TableGateway\TableGateway
的用法示例。
在下文中一共展示了TableGateway::getLastInsertValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Create a resource
*
* @param mixed $data
* @return ApiProblem|mixed
*/
public function create($data)
{
$entity = new ClienteEntity();
$data = json_decode(json_encode($data), true);
$entity->exchangeArray($data);
$data = $entity->getArrayCopy();
$this->tableGateway->insert($data);
$data['id'] = $this->tableGateway->getLastInsertValue();
return $data;
}
示例2: create
/**
* @param array $data
* @return object
*/
public function create(array $data)
{
$this->table->insert($data);
$id = $this->table->getLastInsertValue();
$entity = $this->find($id);
if (!$entity) {
throw new \Exception("Entity not created?");
}
return $entity;
}
示例3: persist
/**
* @param AbstractEntity $entity
* @return $this
*/
public function persist(AbstractEntity $entity)
{
$data = $this->hydrator->extract($entity);
if ($this->hasIdentity($entity)) {
$this->gateway->update($data, ['id' => $entity->getId()]);
} else {
$this->gateway->insert($data);
$entity->setId($this->gateway->getLastInsertValue());
}
return $this;
}
示例4: internalSave
/**
* @param AbstractModel $model
*/
protected function internalSave(AbstractModel $model)
{
$pKey = $this->getPrimaryKey();
if (isset($model->id)) {
$this->tableGateway->update($model->toArray(), [$pKey => $model->{$pKey}]);
} else {
$this->tableGateway->insert($model->toArray());
$id = $this->tableGateway->getLastInsertValue();
$model->{$pKey} = $id;
}
}
示例5: insertNode
/**
* Insert node
*
* @param integer $level
* @param integer $nearKey
* @param array $data
* @param array $filter
* @param boolean $useTransaction
* @return integer|string
*/
protected function insertNode($level, $nearKey, array $data, array $filter = [], $useTransaction = true)
{
try {
if ($useTransaction) {
$this->tableGateway->getAdapter()->getDriver()->getConnection()->beginTransaction();
}
$this->tableGateway->update([$this->left => new Expression('IF (' . $this->left . ' > ?, ' . $this->left . ' + 2, ' . $this->left . ')', [$nearKey]), $this->right => new Expression('IF (' . $this->right . ' > ?, ' . $this->right . ' + 2, ' . $this->right . ')', [$nearKey])], [(new Predicate())->greaterThanOrEqualTo($this->right, $nearKey)] + $filter);
$leftKey = $nearKey + 1;
$rightKey = $nearKey + 2;
$level = $level + 1;
// insert a new node
$this->tableGateway->insert([$this->left => $leftKey, $this->right => $rightKey, $this->level => $level] + $data);
$insertId = $this->tableGateway->getLastInsertValue();
// update parent info
if (false !== ($parent = $this->getParentNode($leftKey, $rightKey, $level, $filter))) {
$this->tableGateway->update([$this->parent => $parent[$this->nodeId]], [$this->nodeId => $insertId]);
}
if ($useTransaction) {
$this->tableGateway->getAdapter()->getDriver()->getConnection()->commit();
}
} catch (Exception $e) {
if ($useTransaction) {
$this->tableGateway->getAdapter()->getDriver()->getConnection()->rollback();
}
ApplicationErrorLogger::log($e);
return $e->getMessage();
}
return $insertId;
}
示例6: indexAction
/**
* Create easypay trade.
* @see \Zend\Mvc\Controller\AbstractActionController::indexAction()
*/
public function indexAction()
{
if ($this->verifyRequest()) {
$this->appendTitle('收银台');
$this->layout()->setVariable('is_cashier_page', true);
$dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
/**
* Check the parameters if they are valid.
*/
$parameters = $this->getRequest()->getQuery();
// if merchant exsist
// if trade|redirect_url|notify_url|sign empty
// if price is a floating numberic
$exception = new \Exception('Parameters is invalid!');
if (empty(trim($parameters['trade'])) || empty(trim($parameters['redirect_url'])) || empty(trim($parameters['notify_url'])) || empty(trim($parameters['sign']))) {
throw $exception;
}
if (!is_numeric(trim($parameters['price']))) {
throw $exception;
}
$merchant_validator = new \Zend\Validator\Db\NoRecordExists(array('table' => 'merchant', 'field' => 'name', 'adapter' => $dbAdapter));
if ($merchant_validator->isValid(intval($parameters['merchant']))) {
throw $exception;
}
/**
* Check if there is an exsist trade.
*/
$GetMerchantIdByName = $this->getServiceLocator()->get('GetMerchantIdByName');
$merchant_id = $GetMerchantIdByName($parameters['merchant']);
$trade = $this->getTrade($merchant_id, trim($parameters['trade']));
$trade_id = null;
$payment_interface_type = null;
if (!empty($trade)) {
// Trade exsist.
if ($trade->pay_status) {
throw new \Exception('Trade had payed before!');
} else {
// Update the exsist trade
$trade->price = trim($parameters['price']);
$trade->redirect_url = trim($parameters['redirect_url']);
$trade->notify_url = trim($parameters['notify_url']);
$trade->save();
$trade_id = $trade->id;
$payment_interface_type = $trade->payment_interface_type;
}
} else {
// Trade not exsist.
// Create a new trade
$tableGateway = new TableGateway('trade', $dbAdapter, new Feature\RowGatewayFeature('id'));
$tableGateway->insert(array('merchant_id' => $merchant_id, 'merchant_trade_id' => trim($parameters['trade']), 'redirect_url' => trim($parameters['redirect_url']), 'notify_url' => trim($parameters['notify_url']), 'price' => trim($parameters['price']), 'pay_status' => 0, 'create_time' => date('Y-n-j H:i:s', time())));
$trade_id = $tableGateway->getLastInsertValue();
}
return array('price' => trim($parameters['price']), 'merchant' => $parameters['merchant'], 'trade' => trim($parameters['trade']), 'selected_payment' => $payment_interface_type);
} else {
throw new \Exception('Bad Reaquest !');
}
}
示例7: persist
/**
* Saves the given rating to the storage system.
*
* @param Rating $rating The rating to persist.
*/
public function persist(Rating $rating)
{
if ($rating->getId()) {
$this->gateway->update(array('typeId' => $rating->getTypeId(), 'userId' => $rating->getUserId(), 'rating' => $rating->getRating()), array('id' => $rating->getId()));
} else {
$this->gateway->insert(array('typeId' => $rating->getTypeId(), 'userId' => $rating->getUserId(), 'rating' => $rating->getRating()));
$id = $this->gateway->getLastInsertValue();
$rating->setId($id);
}
}
示例8: insert
/**
* Adds a data
*/
public function insert()
{
$id = $this->table->insert($this->data);
if (is_null($id)) {
if (array_key_exists('firephp', $GLOBALS)) {
$GLOBALS['firephp']->error('Error on query ' . $this->table->getSql()->getSqlPlatform()->getSqlString($this->table->getAdapter()->getPlatform()));
}
throw new Exception('Error on query ' . $this->table->getSql()->getSqlPlatform()->getSqlString($this->table->getAdapter()->getPlatform()));
}
$this->data[$this->primary] = $this->table->getLastInsertValue();
}
示例9: save
/**
* Сохраняет объект в таблице
*
* @param EntityInterface $object
* @throws \Exception
*/
public function save(EntityInterface $object)
{
$data = array();
foreach ($this->fields as $field) {
$data[$field] = $object->{$field};
}
$id = $object->getKeyValue();
if (null === $id) {
$this->tableGateway->insert($data);
$object->{$object->getKeyName()} = $this->tableGateway->getLastInsertValue();
} else {
if ($this->getByKey($id, $object->getKeyName())) {
$this->tableGateway->update($data, array($object->getKeyName() => $id));
} else {
throw new \Exception('row with ' . $id . ' id does not exist');
}
}
}
示例10: create
/**
* {@inheritdoc}
*
* {@inheritdoc}
*/
public function create($itemData, $rewriteIfExist = false)
{
$identifier = $this->getIdentifier();
$adapter = $this->dbTable->getAdapter();
// begin Transaction
$errorMsg = 'Can\'t start insert transaction';
$adapter->getDriver()->getConnection()->beginTransaction();
try {
if (isset($itemData[$identifier]) && $rewriteIfExist) {
$errorMsg = 'Can\'t delete item with "id" = ' . $itemData[$identifier];
$this->dbTable->delete(array($identifier => $itemData[$identifier]));
}
$errorMsg = 'Can\'t insert item';
$rowsCount = $this->dbTable->insert($itemData);
$adapter->getDriver()->getConnection()->commit();
} catch (\Exception $e) {
$adapter->getDriver()->getConnection()->rollback();
throw new DataStoresException($errorMsg, 0, $e);
}
$id = $this->dbTable->getLastInsertValue();
$newItem = array_merge(array($identifier => $id), $itemData);
return $newItem;
}
示例11: _create
protected function _create($itemData, $rewriteIfExist = false)
{
$identifier = $this->getIdentifier();
if ($rewriteIfExist) {
if (isset($itemData[$identifier])) {
$this->deleteIfExist($itemData, $identifier);
} else {
if (isset($itemData[0]) && isset($itemData[0][$identifier])) {
foreach ($itemData as $item) {
$this->deleteIfExist($item, $identifier);
}
}
}
}
$this->dbTable->insert($itemData);
if (!isset($itemData[$identifier])) {
$id = $this->dbTable->getLastInsertValue();
$newItem = $this->read($id);
} else {
$newItem = $itemData;
}
return $newItem;
}
示例12: testGetLastInsertValue
/**
* @covers Zend\Db\TableGateway\TableGateway::getLastInsertValue
*/
public function testGetLastInsertValue()
{
$this->table->insert(array('foo' => 'bar'));
$this->assertEquals(10, $this->table->getLastInsertValue());
}
示例13: save
public function save($version)
{
$this->tableGateway->insert(['version' => $version]);
return $this->tableGateway->getLastInsertValue();
}
示例14: index05Action
public function index05Action()
{
$table = "user";
$adapter = $this->getServiceLocator()->get("db_books");
$tableGateway = new TableGateway($table, $adapter);
$insertObj = new Insert("user");
$insertObj->columns(array("name", "email"))->values(array("name" => "Armasky", "email" => "ak@hotmail.com"));
$tableGateway->insertWith($insertObj);
//last record inserted
echo $tableGateway->getLastInsertValue();
return false;
}
示例15: addSimpleData
public function addSimpleData($table, $data)
{
$tableGateway = new TableGateway($table, $this->dbAdapter);
$tableGateway->insert($data);
return $tableGateway->getLastInsertValue();
}