本文整理匯總了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());
}
}
示例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));
}
}
}
示例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');
}
示例4: save
public function save(Order $order)
{
$data = $order->jsonSerialize();
unset($data['id']);
$this->connection->insert($this->getTableName(), $data);
$order->setId($this->connection->lastInsertId());
}
示例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));
}
}
}
示例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();
}
}
示例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;
}
示例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');
}
示例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);
}
示例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));
}
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}