当前位置: 首页>>代码示例>>PHP>>正文


PHP Connection::lastInsertId方法代码示例

本文整理汇总了PHP中Doctrine\DBAL\Connection::lastInsertId方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::lastInsertId方法的具体用法?PHP Connection::lastInsertId怎么用?PHP Connection::lastInsertId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\DBAL\Connection的用法示例。


在下文中一共展示了Connection::lastInsertId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: insertTableRows

 /**
  * @param string $tableName
  * @param array $rows
  */
 protected function insertTableRows($tableName, array $rows)
 {
     foreach ($rows as $rowKey => $values) {
         $this->connection->insert($tableName, $this->parser->parse($values));
         $this->parser->addReference($rowKey, $this->connection->lastInsertId());
     }
 }
开发者ID:comphppuebla,项目名称:dbal-fixtures,代码行数:11,代码来源:ConnectionPersister.php

示例2: save

 /**
  * Saves the pool to the database.
  *
  * @param \MusicBox\Entity\Like $pool
  */
 public function save($pool)
 {
     $poolData = array('address_id' => $pool->getAddress()->getId(), 'access_info' => $pool->getAccessInfo());
     if ($pool->getId()) {
         $this->db->update('pools', $poolData, array('pool_id' => $pool->getId()));
         $newFile = $this->handleFileUpload($item);
         if ($newFile) {
             $poolData['image'] = $pool->getImage();
         }
     } else {
         // The pool is new, note the creation timestamp.
         $poolData['created_at'] = time();
         $this->db->insert('pools', $poolData);
         // Get the id of the newly created pool and set it on the entity.
         $id = $this->db->lastInsertId();
         $pool->setId($id);
         // If a new image was uploaded, update the pool with the new
         // filename.
         $newFile = $this->handleFileUpload($pool);
         if ($newFile) {
             $newData = array('image' => $pool->getImage());
             $this->db->update('pools', $newData, array('pool_id' => $id));
         }
     }
 }
开发者ID:stupae,项目名称:Akins-Parker-MikeO-Brien,代码行数:30,代码来源:PoolRepository.php

示例3: addJobToQueue

 /**
  * @inheritdoc
  */
 public function addJobToQueue(Queue $queue, Job &$job)
 {
     $qb = $this->connection->createQueryBuilder();
     $qb->insert($this->getQueueTableName())->values([$this->columns['__CLASS__'] => ':class', $this->columns[JobReflector::PROPERTY_QUEUE] => ':queue', $this->columns[JobReflector::PROPERTY_CREATED] => ':created', $this->columns[JobReflector::PROPERTY_SCHEDULE] => ':schedule', $this->columns[JobReflector::PROPERTY_FAILED] => ':failed', $this->columns[JobReflector::PROPERTY_FINISHED] => ':finished', $this->columns[JobReflector::PROPERTY_RESULT] => ':result', $this->columns[JobReflector::PROPERTY_PROGRESS] => ':progress', $this->columns[JobReflector::PROPERTY_LAST_ATTEMPT] => ':lastAttempt', $this->columns[JobReflector::PROPERTY_TIMEOUT] => ':timeout', $this->columns[JobReflector::PROPERTY_RETRY_COUNT] => ':retryCount', $this->columns[JobReflector::PROPERTY_RETRY] => ':retry', $this->columns[JobReflector::PROPERTY_VERSION] => ':version', $this->columns[JobReflector::PROPERTY_PARAMETERS] => ':parameters'])->setParameters(['class' => get_class($job), 'queue' => $queue->getName(), 'created' => (new DateTimeImmutable())->format('Y-m-d H:i:s'), 'schedule' => JobReflector::getSchedule($job) ? JobReflector::getSchedule($job)->format('Y-m-d H:i:s') : (new DateTimeImmutable())->format('Y-m-d H:i:s'), 'failed' => false, 'finished' => null, 'result' => null, 'progress' => null, 'lastAttempt' => null, 'timeout' => null, 'retryCount' => 0, 'retry' => false, 'version' => JobReflector::getVersion($job), 'parameters' => json_encode(JobReflector::getParameters($job))]);
     $qb->execute();
     return $this->connection->lastInsertId('job_seq');
 }
开发者ID:JackPrice,项目名称:phpq,代码行数:10,代码来源:DoctrineDBALDriver.php

示例4: save

 public function save(Order $order)
 {
     $data = $order->jsonSerialize();
     unset($data['id']);
     $this->connection->insert($this->getTableName(), $data);
     $order->setId($this->connection->lastInsertId());
 }
开发者ID:Basster,项目名称:hs-bremen-web-api,代码行数:7,代码来源:OrderRepository.php

示例5: save

 /**
  * Saves the artist to the database.
  *
  * @param \MusicBox\Entity\Artist $artist
  */
 public function save($artist)
 {
     $artistData = array('name' => $artist->getName(), 'short_biography' => $artist->getShortBiography(), 'biography' => $artist->getBiography(), 'soundcloud_url' => $artist->getSoundCloudUrl(), 'image' => $artist->getImage());
     if ($artist->getId()) {
         // If a new image was uploaded, make sure the filename gets set.
         $newFile = $this->handleFileUpload($artist);
         if ($newFile) {
             $artistData['image'] = $artist->getImage();
         }
         $this->db->update('artists', $artistData, array('artist_id' => $artist->getId()));
     } else {
         // The artist is new, note the creation timestamp.
         $artistData['created_at'] = time();
         $this->db->insert('artists', $artistData);
         // Get the id of the newly created artist and set it on the entity.
         $id = $this->db->lastInsertId();
         $artist->setId($id);
         // If a new image was uploaded, update the artist with the new
         // filename.
         $newFile = $this->handleFileUpload($artist);
         if ($newFile) {
             $newData = array('image' => $artist->getImage());
             $this->db->update('artists', $newData, array('artist_id' => $id));
         }
     }
 }
开发者ID:juananruiz,项目名称:musicbox,代码行数:31,代码来源:ArtistRepository.php

示例6: doStart

 protected function doStart($parentId)
 {
     $this->conn->beginTransaction();
     $platform = $this->conn->getDatabasePlatform();
     $variables = $this->variables;
     $executionNextPollDate = null;
     if (isset($variables['batchWaitInterval'])) {
         if (!$variables['batchWaitInterval'] instanceof \DateInterval) {
             throw new \ezcWorkflowExecutionException("Specified batch waiting interval has to be instance of DateInterval!");
         }
         $executionNextPollDate = new \DateTime("now");
         $executionNextPollDate->add($variables['batchWaitInterval']);
         $executionNextPollDate = $executionNextPollDate->format($platform->getDateTimeFormatString());
     }
     $serializer = $this->options->getSerializer();
     $now = new \DateTime("now");
     $data = array('workflow_id' => (int) $this->workflow->id, 'execution_parent' => $parentId, 'execution_started' => $now->format($platform->getDateTimeFormatString()), 'execution_variables' => $serializer->serialize($variables), 'execution_waiting_for' => $serializer->serialize($this->waitingFor), 'execution_threads' => $serializer->serialize($this->threads), 'execution_next_thread_id' => (int) $this->nextThreadId, 'execution_next_poll_date' => $executionNextPollDate);
     if ($platform->prefersSequences()) {
         $data['execution_id'] = (int) $this->conn->fetchColumn($platform->getSequenceNextValSQL($this->options->executionSequence()));
         $this->id = $data['execution_id'];
     }
     $this->conn->insert($this->options->executionTable(), $data);
     // execution_id
     if (!$platform->prefersSequences()) {
         $this->id = (int) $this->conn->lastInsertId();
     }
 }
开发者ID:beberlei,项目名称:Doctrine-Workflow,代码行数:27,代码来源:DoctrineExecution.php

示例7: save

 /**
  * {@inheritdoc}
  */
 public function save(StudyInterface $study)
 {
     $qb = $this->connection->createQueryBuilder();
     if ($study->getId() === null) {
         $qb->insert('vbee_study')->values(['name' => '?', 'description' => '?', 'graduation' => '?', 'startDate' => '?', 'endDate' => '?', 'personId' => '?'])->setParameter(0, $study->getName())->setParameter(1, $study->getDescription())->setParameter(2, $study->getGraduation())->setParameter(3, $study->getStartDate()->format('Y-m-d'))->setParameter(4, $study->getEndDate()->format('Y-m-d'))->setParameter(5, $study->getPerson()->getId())->execute();
         $study->setId($this->connection->lastInsertId());
     } else {
         $qb->update('vbee_study')->set('name', '?')->set('description', '?')->set('graduation', '?')->set('startDate', '?')->set('endDate', '?')->set('personId', '?')->where('id = ?')->setParameter(0, $study->getName())->setParameter(1, $study->getDescription())->setParameter(2, $study->getGraduation())->setParameter(3, $study->getStartDate()->format('Y-m-d'))->setParameter(4, $study->getEndDate()->format('Y-m-d'))->setParameter(5, $study->getPerson()->getId())->setParameter(6, $study->getId())->execute();
     }
     return $study;
 }
开发者ID:VincentBee,项目名称:vbee_site,代码行数:14,代码来源:StudyRepository.php

示例8: create

 public function create($values)
 {
     $query = $this->db->createQueryBuilder()->insert('articles');
     // Append parameters to insert to the query
     foreach ($values as $key => $value) {
         $query = $query->setValue($key, ':' . $key)->setParameter(':' . $key, $value);
     }
     $query->execute();
     // @TODO: Check if this works in MariaDB
     return $this->db->lastInsertId('articles_id_seq');
 }
开发者ID:etu,项目名称:0bRSS,代码行数:11,代码来源:Articles.php

示例9: save

 public function save($user)
 {
     $userData = array('name' => $user->getName(), 'email' => $user->getEmail(), 'password' => $user->getPassword(), 'joinTime' => $user->getJoinTime(), 'registerIp' => $user->getRegisterIp(), 'sharedKey' => $user->getSharedKey(), 'integration' => $user->getIntegration(), 'shareKey' => $user->getShareKey());
     $this->db->insert('user', $userData);
     $id = $this->db->lastInsertId();
     $user->setId($id);
 }
开发者ID:yuyan2077,项目名称:ResourcesStore,代码行数:7,代码来源:UserRepository.php

示例10: save

 /**
  * Saves the user to the database.
  *
  * @param \MusicBox\Entity\User $user
  */
 public function save($user)
 {
     $userData = array('username' => $user->getUsername(), 'mail' => $user->getMail(), 'role' => $user->getRole());
     // If the password was changed, re-encrypt it.
     if (strlen($user->getPassword()) != 88) {
         $userData['salt'] = uniqid(mt_rand());
         $userData['password'] = $this->encoder->encodePassword($user->getPassword(), $userData['salt']);
     }
     if ($user->getId()) {
         // If a new image was uploaded, make sure the filename gets set.
         $newFile = $this->handleFileUpload($user);
         if ($newFile) {
             $userData['image'] = $user->getImage();
         }
         $this->db->update('users', $userData, array('user_id' => $user->getId()));
     } else {
         // The user is new, note the creation timestamp.
         $userData['created_at'] = time();
         $this->db->insert('users', $userData);
         // Get the id of the newly created user and set it on the entity.
         $id = $this->db->lastInsertId();
         $user->setId($id);
         // If a new image was uploaded, update the user with the new
         // filename.
         $newFile = $this->handleFileUpload($user);
         if ($newFile) {
             $newData = array('image' => $user->getImage());
             $this->db->update('users', $newData, array('user_id' => $id));
         }
     }
 }
开发者ID:nix5longhorn,项目名称:musicbox,代码行数:36,代码来源:UserRepository.php

示例11: create

 public function create(CacheRecord $cacheRecord)
 {
     $this->db->insert($this->entityTable, $cacheRecord->toArray());
     if ($this->db->lastInsertId() <= 0) {
         throw new InvalidArgumentException("The insert failed.");
     }
     return $this->db->lastInsertId();
 }
开发者ID:konstantin-s,项目名称:silex-lazycache,代码行数:8,代码来源:CacheRecordSQLMapper.php

示例12: checkAutoincrement

 /**
  * Tests whether autoincrement works
  *
  * @return boolean true if autoincrement works, false otherwise
  */
 protected function checkAutoincrement()
 {
     $this->connection->executeUpdate('INSERT INTO ' . $this->tableName . ' ("text") VALUES ("test")');
     $insertId = $this->connection->lastInsertId();
     $this->connection->executeUpdate('DELETE FROM ' . $this->tableName . ' WHERE "someid" = ?', array($insertId));
     // insert again
     $this->connection->executeUpdate('INSERT INTO ' . $this->tableName . ' ("text") VALUES ("test2")');
     $newInsertId = $this->connection->lastInsertId();
     return $insertId !== $newInsertId;
 }
开发者ID:kenwi,项目名称:core,代码行数:15,代码来源:repairsqliteautoincrement.php

示例13: persistObject

 public function persistObject($object)
 {
     $data = $this->preparePersistChangeSet($object);
     $this->connection->insert($this->getTableName(), $data);
     $class = $this->objectManager->getClassMetadata(get_class($object));
     if (!isset($data[$class->identifier[0]])) {
         $data[$class->identifier[0]] = $this->connection->lastInsertId();
     }
     return $data;
 }
开发者ID:basuritas-php,项目名称:skeleton-mapper,代码行数:10,代码来源:DBALObjectPersister.php

示例14: save

 /**
  * {@inheritdoc}
  */
 public function save(PersonInterface $person)
 {
     $qb = $this->connection->createQueryBuilder();
     if ($person->getId() === null) {
         $qb->insert('vbee_person')->values(['birthDate' => '?', 'description' => '?', 'email' => '?', 'familyName' => '?', 'gender' => '?', 'givenName' => '?', 'jobTitle' => '?', 'nationality' => '?', 'telephone' => '?'])->setParameter(0, $person->getBirthDate()->format('Y-m-d'))->setParameter(1, $person->getDescription())->setParameter(2, $person->getEmail())->setParameter(3, $person->getFamilyName())->setParameter(4, $person->getGender())->setParameter(5, $person->getGivenName())->setParameter(6, $person->getJobTitle())->setParameter(7, $person->getNationality())->setParameter(8, $person->getTelephone())->execute();
         $person->setId($this->connection->lastInsertId());
     } else {
         $qb->update('vbee_person')->set('birthDate', '?')->set('description', '?')->set('email', '?')->set('familyName', '?')->set('gender', '?')->set('givenName', '?')->set('jobTitle', '?')->set('nationality', '?')->set('telephone', '?')->where('id = ?')->setParameter(0, $person->getBirthDate()->format('Y-m-d'))->setParameter(1, $person->getDescription())->setParameter(2, $person->getEmail())->setParameter(3, $person->getFamilyName())->setParameter(4, $person->getGender())->setParameter(5, $person->getGivenName())->setParameter(6, $person->getJobTitle())->setParameter(7, $person->getNationality())->setParameter(8, $person->getTelephone())->setParameter(9, $person->getId())->execute();
     }
     return $person;
 }
开发者ID:VincentBee,项目名称:vbee_site,代码行数:14,代码来源:PersonRepository.php

示例15: save

 /**
  * Saves the like to the database.
  *
  * @param Like $like
  *
  * @return Like $like
  */
 public function save($like)
 {
     $likeData = array('restaurant_id' => $like->getRestaurant(), 'user_id' => $like->getUser());
     if ($like->getId()) {
         $this->db->update('likes', $likeData, array('id' => $like->getId()));
     } else {
         $this->db->insert('likes', $likeData);
         $last = $this->db->lastInsertId();
         return $this->find($last);
     }
 }
开发者ID:KristenGarnier,项目名称:CommandeRestau,代码行数:18,代码来源:LikeRepository.php


注:本文中的Doctrine\DBAL\Connection::lastInsertId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。