lastInsertId() public méthode

Retrieve the last auto incremet or sequence id.
public lastInsertId ( string $sequenceName = null ) : string
$sequenceName string
Résultat string
 /**
  * Inserts the given UrlWildcard.
  *
  * @param \eZ\Publish\SPI\Persistence\Content\UrlWildcard $urlWildcard
  *
  * @return mixed
  */
 public function insertUrlWildcard(UrlWildcard $urlWildcard)
 {
     /** @var $query \eZ\Publish\Core\Persistence\Database\InsertQuery */
     $query = $this->dbHandler->createInsertQuery();
     $query->insertInto($this->dbHandler->quoteTable('ezurlwildcard'))->set($this->dbHandler->quoteColumn('destination_url'), $query->bindValue(trim($urlWildcard->destinationUrl, '/ '), null, \PDO::PARAM_STR))->set($this->dbHandler->quoteColumn('id'), $this->dbHandler->getAutoIncrementValue('ezurlwildcard', 'id'))->set($this->dbHandler->quoteColumn('source_url'), $query->bindValue(trim($urlWildcard->sourceUrl, '/ '), null, \PDO::PARAM_STR))->set($this->dbHandler->quoteColumn('type'), $query->bindValue($urlWildcard->forward ? 1 : 2, null, \PDO::PARAM_INT));
     $query->prepare()->execute();
     return $this->dbHandler->lastInsertId($this->dbHandler->getSequenceName('ezurlwildcard', 'id'));
 }
 /**
  * Inserts a new relation database record.
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct $createStruct
  *
  * @return int ID the inserted ID
  */
 public function insertRelation(RelationCreateStruct $createStruct)
 {
     $q = $this->dbHandler->createInsertQuery();
     $q->insertInto($this->dbHandler->quoteTable('ezcontentobject_link'))->set($this->dbHandler->quoteColumn('id'), $this->dbHandler->getAutoIncrementValue('ezcontentobject_link', 'id'))->set($this->dbHandler->quoteColumn('contentclassattribute_id'), $q->bindValue((int) $createStruct->sourceFieldDefinitionId, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('from_contentobject_id'), $q->bindValue($createStruct->sourceContentId, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('from_contentobject_version'), $q->bindValue($createStruct->sourceContentVersionNo, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('relation_type'), $q->bindValue($createStruct->type, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('to_contentobject_id'), $q->bindValue($createStruct->destinationContentId, null, \PDO::PARAM_INT));
     $q->prepare()->execute();
     return $this->dbHandler->lastInsertId($this->dbHandler->getSequenceName('ezcontentobject_link', 'id'));
 }
 /**
  * Inserts a new object state group into database
  *
  * @param \eZ\Publish\SPI\Persistence\Content\ObjectState\Group $objectStateGroup
  */
 public function insertObjectStateGroup(Group $objectStateGroup)
 {
     $query = $this->dbHandler->createInsertQuery();
     $query->insertInto($this->dbHandler->quoteTable('ezcobj_state_group'))->set($this->dbHandler->quoteColumn('id'), $this->dbHandler->getAutoIncrementValue('ezcobj_state_group', 'id'))->set($this->dbHandler->quoteColumn('default_language_id'), $query->bindValue($this->maskGenerator->generateLanguageIndicator($objectStateGroup->defaultLanguage, false), null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('identifier'), $query->bindValue($objectStateGroup->identifier))->set($this->dbHandler->quoteColumn('language_mask'), $query->bindValue($this->generateLanguageMask($objectStateGroup->languageCodes), null, \PDO::PARAM_INT));
     $query->prepare()->execute();
     $objectStateGroup->id = (int) $this->dbHandler->lastInsertId($this->dbHandler->getSequenceName('ezcobj_state_group', 'id'));
     $this->insertObjectStateGroupTranslations($objectStateGroup);
 }
 /**
  * Inserts a $fieldDefinition for $typeId.
  *
  * @param mixed $typeId
  * @param int $status
  * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDefinition
  * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageFieldDef
  *
  * @return mixed Field definition ID
  */
 public function insertFieldDefinition($typeId, $status, FieldDefinition $fieldDefinition, StorageFieldDefinition $storageFieldDef)
 {
     $q = $this->dbHandler->createInsertQuery();
     $q->insertInto($this->dbHandler->quoteTable('ezcontentclass_attribute'));
     $q->set($this->dbHandler->quoteColumn('id'), isset($fieldDefinition->id) ? $q->bindValue($fieldDefinition->id, null, \PDO::PARAM_INT) : $this->dbHandler->getAutoIncrementValue('ezcontentclass_attribute', 'id'))->set($this->dbHandler->quoteColumn('contentclass_id'), $q->bindValue($typeId, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('version'), $q->bindValue($status, null, \PDO::PARAM_INT));
     $this->setCommonFieldColumns($q, $fieldDefinition, $storageFieldDef);
     $q->prepare()->execute();
     if (!isset($fieldDefinition->id)) {
         return $this->dbHandler->lastInsertId($this->dbHandler->getSequenceName('ezcontentclass_attribute', 'id'));
     }
     return $fieldDefinition->id;
 }
 /**
  * Creates a new synonym using the given $keyword for tag $tag.
  *
  * @param \Netgen\TagsBundle\SPI\Persistence\Tags\SynonymCreateStruct $createStruct
  * @param array $tag
  *
  * @return \Netgen\TagsBundle\SPI\Persistence\Tags\Tag
  */
 public function createSynonym(SynonymCreateStruct $createStruct, array $tag)
 {
     $query = $this->handler->createInsertQuery();
     $query->insertInto($this->handler->quoteTable('eztags'))->set($this->handler->quoteColumn('id'), $this->handler->getAutoIncrementValue('eztags', 'id'))->set($this->handler->quoteColumn('parent_id'), $query->bindValue($tag['parent_id'], null, PDO::PARAM_INT))->set($this->handler->quoteColumn('main_tag_id'), $query->bindValue($createStruct->mainTagId, null, PDO::PARAM_INT))->set($this->handler->quoteColumn('keyword'), $query->bindValue($createStruct->keywords[$createStruct->mainLanguageCode], null, PDO::PARAM_STR))->set($this->handler->quoteColumn('depth'), $query->bindValue($tag['depth'], null, PDO::PARAM_INT))->set($this->handler->quoteColumn('path_string'), $query->bindValue('dummy'))->set($this->handler->quoteColumn('remote_id'), $query->bindValue($createStruct->remoteId, null, PDO::PARAM_STR))->set($this->handler->quoteColumn('main_language_id'), $query->bindValue($this->languageHandler->loadByLanguageCode($createStruct->mainLanguageCode)->id, null, PDO::PARAM_INT))->set($this->handler->quoteColumn('language_mask'), $query->bindValue($this->generateLanguageMask($createStruct->keywords, is_bool($createStruct->alwaysAvailable) ? $createStruct->alwaysAvailable : true), null, PDO::PARAM_INT));
     $query->prepare()->execute();
     $synonymId = $this->handler->lastInsertId($this->handler->getSequenceName('eztags', 'id'));
     $synonymPathString = $this->getSynonymPathString($synonymId, $tag['path_string']);
     $query = $this->handler->createUpdateQuery();
     $query->update($this->handler->quoteTable('eztags'))->set($this->handler->quoteColumn('path_string'), $query->bindValue($synonymPathString, null, PDO::PARAM_STR))->where($query->expr->eq($this->handler->quoteColumn('id'), $query->bindValue($synonymId, null, PDO::PARAM_INT)));
     $query->prepare()->execute();
     $this->insertTagKeywords($synonymId, $createStruct->keywords, $createStruct->mainLanguageCode, $createStruct->alwaysAvailable);
     return $synonymId;
 }
 /**
  * Adds limitations to an existing policy.
  *
  * @param int $policyId
  * @param array $limitations
  */
 public function addPolicyLimitations($policyId, array $limitations)
 {
     foreach ($limitations as $identifier => $values) {
         $query = $this->handler->createInsertQuery();
         $query->insertInto($this->handler->quoteTable('ezpolicy_limitation'))->set($this->handler->quoteColumn('id'), $this->handler->getAutoIncrementValue('ezpolicy_limitation', 'id'))->set($this->handler->quoteColumn('identifier'), $query->bindValue($identifier))->set($this->handler->quoteColumn('policy_id'), $query->bindValue($policyId, null, \PDO::PARAM_INT));
         $query->prepare()->execute();
         $limitationId = $this->handler->lastInsertId($this->handler->getSequenceName('ezpolicy_limitation', 'id'));
         foreach ($values as $value) {
             $query = $this->handler->createInsertQuery();
             $query->insertInto($this->handler->quoteTable('ezpolicy_limitation_value'))->set($this->handler->quoteColumn('id'), $this->handler->getAutoIncrementValue('ezpolicy_limitation_value', 'id'))->set($this->handler->quoteColumn('value'), $query->bindValue($value))->set($this->handler->quoteColumn('limitation_id'), $query->bindValue($limitationId, null, \PDO::PARAM_INT));
             $query->prepare()->execute();
         }
     }
 }
 /**
  * Creates a new location in given $parentNode.
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct $createStruct
  * @param array $parentNode
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Location
  */
 public function create(CreateStruct $createStruct, array $parentNode)
 {
     $location = new Location();
     /** @var $query \eZ\Publish\Core\Persistence\Database\InsertQuery */
     $query = $this->handler->createInsertQuery();
     $query->insertInto($this->handler->quoteTable('ezcontentobject_tree'))->set($this->handler->quoteColumn('contentobject_id'), $query->bindValue($location->contentId = $createStruct->contentId, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('contentobject_is_published'), $query->bindValue(1, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('contentobject_version'), $query->bindValue($createStruct->contentVersion, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('depth'), $query->bindValue($location->depth = $parentNode['depth'] + 1, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('is_hidden'), $query->bindValue($location->hidden = $createStruct->hidden, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('is_invisible'), $query->bindValue($location->invisible = $createStruct->invisible, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('modified_subnode'), $query->bindValue(time(), null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('node_id'), $this->handler->getAutoIncrementValue('ezcontentobject_tree', 'node_id'))->set($this->handler->quoteColumn('parent_node_id'), $query->bindValue($location->parentId = $parentNode['node_id'], null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('path_identification_string'), $query->bindValue($location->pathIdentificationString = $createStruct->pathIdentificationString, null, \PDO::PARAM_STR))->set($this->handler->quoteColumn('path_string'), $query->bindValue('dummy'))->set($this->handler->quoteColumn('priority'), $query->bindValue($location->priority = $createStruct->priority, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('remote_id'), $query->bindValue($location->remoteId = $createStruct->remoteId, null, \PDO::PARAM_STR))->set($this->handler->quoteColumn('sort_field'), $query->bindValue($location->sortField = $createStruct->sortField, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('sort_order'), $query->bindValue($location->sortOrder = $createStruct->sortOrder, null, \PDO::PARAM_INT));
     $query->prepare()->execute();
     $location->id = $this->handler->lastInsertId($this->handler->getSequenceName('ezcontentobject_tree', 'node_id'));
     $mainLocationId = $createStruct->mainLocationId === true ? $location->id : $createStruct->mainLocationId;
     $location->pathString = $parentNode['path_string'] . $location->id . '/';
     /** @var $query \eZ\Publish\Core\Persistence\Database\UpdateQuery */
     $query = $this->handler->createUpdateQuery();
     $query->update($this->handler->quoteTable('ezcontentobject_tree'))->set($this->handler->quoteColumn('path_string'), $query->bindValue($location->pathString))->set($this->handler->quoteColumn('main_node_id'), $query->bindValue($mainLocationId, null, \PDO::PARAM_INT))->where($query->expr->eq($this->handler->quoteColumn('node_id'), $query->bindValue($location->id, null, \PDO::PARAM_INT)));
     $query->prepare()->execute();
     return $location;
 }
 /**
  * Returns next value for "id" column.
  *
  * @return mixed
  */
 public function getNextId()
 {
     $sequence = $this->dbHandler->getSequenceName('ezurlalias_ml_incr', 'id');
     /** @var $query \eZ\Publish\Core\Persistence\Database\InsertQuery */
     $query = $this->dbHandler->createInsertQuery();
     $query->insertInto($this->dbHandler->quoteTable("ezurlalias_ml_incr"));
     // ezcDatabase does not abstract the "auto increment id"
     // INSERT INTO ezurlalias_ml_incr VALUES(DEFAULT) is not an option due
     // to this mysql bug: http://bugs.mysql.com/bug.php?id=42270
     // as a result we are forced to check which database is currently used
     // to generate the correct SQL query
     // see https://jira.ez.no/browse/EZP-20652
     if ($this->dbHandler->useSequences()) {
         $query->set($this->dbHandler->quoteColumn("id"), "nextval('{$sequence}')");
     } else {
         $query->set($this->dbHandler->quoteColumn("id"), $query->bindValue(null, null, \PDO::PARAM_NULL));
     }
     $query->prepare()->execute();
     return $this->dbHandler->lastInsertId($sequence);
 }