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


PHP IDBConnection::lastInsertId方法代码示例

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


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

示例1: insert

 /**
  * Quick insert record
  * @param $table
  * @param array $columnData
  * @return \Doctrine\DBAL\Driver\Statement
  */
 public function insert($table, array $columnData)
 {
     $columns = array_keys($columnData);
     $sql = sprintf("INSERT INTO %s (%s) VALUES (%s);", $table, implode(', ', $columns), implode(', ', array_fill(0, count($columnData), '?')));
     $this->db->executeQuery($sql, array_values($columnData));
     return $this->db->lastInsertId($table);
 }
开发者ID:bogolubov,项目名称:owncollab_talks-1,代码行数:13,代码来源:connect.php

示例2: createShare

 private function createShare($type, $sourceId, $recipient, $targetName, $permissions, $parentId = null)
 {
     $qb = $this->connection->getQueryBuilder();
     $values = ['share_type' => $qb->expr()->literal($type), 'share_with' => $qb->expr()->literal($recipient), 'uid_owner' => $qb->expr()->literal('user1'), 'item_type' => $qb->expr()->literal('folder'), 'item_source' => $qb->expr()->literal($sourceId), 'item_target' => $qb->expr()->literal('/' . $sourceId), 'file_source' => $qb->expr()->literal($sourceId), 'file_target' => $qb->expr()->literal($targetName), 'permissions' => $qb->expr()->literal($permissions), 'stime' => $qb->expr()->literal(time())];
     if ($parentId !== null) {
         $values['parent'] = $qb->expr()->literal($parentId);
     }
     $qb->insert('share')->values($values)->execute();
     return $this->connection->lastInsertId('*PREFIX*share');
 }
开发者ID:GitHubUser4234,项目名称:core,代码行数:10,代码来源:RepairUnmergedSharesTest.php

示例3: createShare

 /**
  * @param string $shareType
  * @param string $shareWith
  * @param null|int $parent
  * @return int
  */
 protected function createShare($shareType, $shareWith, $parent)
 {
     $qb = $this->connection->getQueryBuilder();
     $shareValues = ['share_type' => $qb->expr()->literal($shareType), 'share_with' => $qb->expr()->literal($shareWith), 'uid_owner' => $qb->expr()->literal('user1'), 'item_type' => $qb->expr()->literal('folder'), 'item_source' => $qb->expr()->literal(123), 'item_target' => $qb->expr()->literal('/123'), 'file_source' => $qb->expr()->literal(123), 'file_target' => $qb->expr()->literal('/test'), 'permissions' => $qb->expr()->literal(1), 'stime' => $qb->expr()->literal(time()), 'expiration' => $qb->expr()->literal('2015-09-25 00:00:00')];
     if ($parent) {
         $shareValues['parent'] = $qb->expr()->literal($parent);
     }
     $qb = $this->connection->getQueryBuilder();
     $qb->insert('share')->values($shareValues)->execute();
     return $this->connection->lastInsertId('*PREFIX*share');
 }
开发者ID:rchicoli,项目名称:owncloud-core,代码行数:17,代码来源:OldGroupMembershipSharesTest.php

示例4: addServer

 /**
  * add server to the list of trusted ownCloud servers
  *
  * @param string $url
  * @return int
  * @throws HintException
  */
 public function addServer($url)
 {
     $hash = $this->hash($url);
     $query = $this->connection->getQueryBuilder();
     $query->insert($this->dbTable)->values(['url' => $query->createParameter('url'), 'url_hash' => $query->createParameter('url_hash')])->setParameter('url', $url)->setParameter('url_hash', $hash);
     $result = $query->execute();
     if ($result) {
         return (int) $this->connection->lastInsertId('*PREFIX*' . $this->dbTable);
     } else {
         $message = 'Internal failure, Could not add ownCloud as trusted server: ' . $url;
         $message_t = $this->l->t('Could not add server');
         throw new HintException($message, $message_t);
     }
 }
开发者ID:reverserob,项目名称:core,代码行数:21,代码来源:dbhandler.php

示例5: createCacheEntry

 private function createCacheEntry($internalPath, $storageId)
 {
     $this->connection->insertIfNotExist('*PREFIX*filecache', ['storage' => $storageId, 'path' => $internalPath, 'path_hash' => md5($internalPath), 'parent' => -1, 'name' => basename($internalPath), 'mimetype' => 0, 'mimepart' => 0, 'size' => 0, 'storage_mtime' => 0, 'encrypted' => 0, 'unencrypted_size' => 0, 'etag' => '', 'permissions' => 31], ['storage', 'path_hash']);
     $id = (int) $this->connection->lastInsertId('*PREFIX*filecache');
     $this->fileIds[] = $id;
     return $id;
 }
开发者ID:rchicoli,项目名称:owncloud-core,代码行数:7,代码来源:UserMountCacheTest.php

示例6: getLastInsertId

 /**
  * Used to get the id of the last inserted element
  * @return int
  * @throws \BadMethodCallException When being called before an insert query has been run.
  */
 public function getLastInsertId()
 {
     $from = $this->getQueryPart('from');
     if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT && !empty($from)) {
         return (int) $this->connection->lastInsertId($from['table']);
     }
     throw new \BadMethodCallException('Invalid call to getLastInsertId without using insert() before.');
 }
开发者ID:gwdg,项目名称:core,代码行数:13,代码来源:querybuilder.php

示例7: getLastInsertId

 /**
  * Used to get the id of the last inserted element
  * @return int
  * @throws \BadMethodCallException When being called before an insert query has been run.
  */
 public function getLastInsertId()
 {
     if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT && $this->lastInsertedTable) {
         // lastInsertId() needs the prefix but no quotes
         $table = $this->prefixTableName($this->lastInsertedTable);
         return (int) $this->connection->lastInsertId($table);
     }
     throw new \BadMethodCallException('Invalid call to getLastInsertId without using insert() before.');
 }
开发者ID:rchicoli,项目名称:owncloud-core,代码行数:14,代码来源:QueryBuilder.php

示例8: addMount

 /**
  * Add a mount to the database
  *
  * @param string $mountPoint
  * @param string $storageBackend
  * @param string $authBackend
  * @param int $priority
  * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL
  * @return int the id of the new mount
  */
 public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type)
 {
     if (!$priority) {
         $priority = 100;
     }
     $builder = $this->connection->getQueryBuilder();
     $query = $builder->insert('external_mounts')->values(['mount_point' => $builder->createNamedParameter($mountPoint, \PDO::PARAM_STR), 'storage_backend' => $builder->createNamedParameter($storageBackend, \PDO::PARAM_STR), 'auth_backend' => $builder->createNamedParameter($authBackend, \PDO::PARAM_STR), 'priority' => $builder->createNamedParameter($priority, \PDO::PARAM_INT), 'type' => $builder->createNamedParameter($type, \PDO::PARAM_INT)]);
     $query->execute();
     return (int) $this->connection->lastInsertId('external_mounts');
 }
开发者ID:fabricecetic,项目名称:core,代码行数:20,代码来源:dbconfigservice.php

示例9: getLastInsertID

 /**
  * @param $tableName
  * @param $idName
  * @return int
  */
 protected function getLastInsertID($tableName, $idName)
 {
     $id = $this->connection->lastInsertId();
     if ($id) {
         return $id;
     }
     // FIXME !!!! ORACLE WORKAROUND DO NOT COPY
     // FIXME INSTEAD HELP FIXING DOCTRINE
     // FIXME https://github.com/owncloud/core/issues/13303
     // FIXME ALSO FIX https://github.com/owncloud/core/commit/2dd85ec984c12d3be401518f22c90d2327bec07a
     $qb = $this->connection->getQueryBuilder();
     $result = $qb->select($qb->createFunction('MAX(`' . $idName . '`)'))->from($tableName)->execute();
     return (int) $result->fetchColumn();
 }
开发者ID:henkRW,项目名称:core,代码行数:19,代码来源:cleantags.php

示例10: createTag

 /**
  * {@inheritdoc}
  */
 public function createTag($tagName, $userVisible, $userAssignable)
 {
     $userVisible = (int) $userVisible;
     $userAssignable = (int) $userAssignable;
     $query = $this->connection->getQueryBuilder();
     $query->insert(self::TAG_TABLE)->values(['name' => $query->createNamedParameter($tagName), 'visibility' => $query->createNamedParameter($userVisible), 'editable' => $query->createNamedParameter($userAssignable)]);
     try {
         $query->execute();
     } catch (UniqueConstraintViolationException $e) {
         throw new TagAlreadyExistsException('Tag ("' . $tagName . '", ' . $userVisible . ', ' . $userAssignable . ') already exists', 0, $e);
     }
     $tagId = $this->connection->lastInsertId('*PREFIX*' . self::TAG_TABLE);
     return new SystemTag((int) $tagId, $tagName, (bool) $userVisible, (bool) $userAssignable);
 }
开发者ID:kenwi,项目名称:core,代码行数:17,代码来源:systemtagmanager.php

示例11: testGetLastInsertId

 public function testGetLastInsertId()
 {
     $qB = $this->connection->getQueryBuilder();
     try {
         $qB->getLastInsertId();
         $this->fail('getLastInsertId() should throw an exception, when being called before insert()');
     } catch (\BadMethodCallException $e) {
         $this->assertTrue(true);
     }
     $qB->insert('appconfig')->values(['appid' => $qB->expr()->literal('testFirstResult'), 'configkey' => $qB->expr()->literal('testing' . 50), 'configvalue' => $qB->expr()->literal(100 - 50)])->execute();
     $actual = $qB->getLastInsertId();
     $this->assertNotNull($actual);
     $this->assertInternalType('int', $actual);
     $this->assertEquals($this->connection->lastInsertId('*PREFIX*appconfig'), $actual);
 }
开发者ID:gwdg,项目名称:core,代码行数:15,代码来源:querybuildertest.php

示例12: createSubscription

 /**
  * Creates a new subscription for a principal.
  *
  * If the creation was a success, an id must be returned that can be used to reference
  * this subscription in other methods, such as updateSubscription.
  *
  * @param string $principalUri
  * @param string $uri
  * @param array $properties
  * @return mixed
  */
 function createSubscription($principalUri, $uri, array $properties)
 {
     if (!isset($properties['{http://calendarserver.org/ns/}source'])) {
         throw new Forbidden('The {http://calendarserver.org/ns/}source property is required when creating subscriptions');
     }
     $values = ['principaluri' => $principalUri, 'uri' => $uri, 'source' => $properties['{http://calendarserver.org/ns/}source']->getHref(), 'lastmodified' => time()];
     foreach ($this->subscriptionPropertyMap as $xmlName => $dbName) {
         if (isset($properties[$xmlName])) {
             $values[$dbName] = $properties[$xmlName];
             $fieldNames[] = $dbName;
         }
     }
     $query = $this->db->getQueryBuilder();
     $query->insert('calendarsubscriptions')->values(['principaluri' => $query->createNamedParameter($values['principaluri']), 'uri' => $query->createNamedParameter($values['uri']), 'source' => $query->createNamedParameter($values['source']), 'lastmodified' => $query->createNamedParameter($values['lastmodified'])])->execute();
     return $this->db->lastInsertId('*PREFIX*calendarsubscriptions');
 }
开发者ID:farukuzun,项目名称:core-1,代码行数:27,代码来源:caldavbackend.php

示例13: put

 /**
  * store meta data for a file or folder
  *
  * @param string $file
  * @param array $data
  *
  * @return int file id
  * @throws \RuntimeException
  */
 public function put($file, array $data)
 {
     if (($id = $this->getId($file)) > -1) {
         $this->update($id, $data);
         return $id;
     } else {
         // normalize file
         $file = $this->normalize($file);
         if (isset($this->partial[$file])) {
             //add any saved partial data
             $data = array_merge($this->partial[$file], $data);
             unset($this->partial[$file]);
         }
         $requiredFields = array('size', 'mtime', 'mimetype');
         foreach ($requiredFields as $field) {
             if (!isset($data[$field])) {
                 //data not complete save as partial and return
                 $this->partial[$file] = $data;
                 return -1;
             }
         }
         $data['path'] = $file;
         $data['parent'] = $this->getParentId($file);
         $data['name'] = \OC_Util::basename($file);
         list($queryParts, $params) = $this->buildParts($data);
         $queryParts[] = '`storage`';
         $params[] = $this->getNumericStorageId();
         $queryParts = array_map(function ($item) {
             return trim($item, "`");
         }, $queryParts);
         $values = array_combine($queryParts, $params);
         if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values, ['storage', 'path_hash'])) {
             return (int) $this->connection->lastInsertId('*PREFIX*filecache');
         }
         // The file was created in the mean time
         if (($id = $this->getId($file)) > -1) {
             $this->update($id, $data);
             return $id;
         } else {
             throw new \RuntimeException('File entry could not be inserted with insertIfNotExist() but could also not be selected with getId() in order to perform an update. Please try again.');
         }
     }
 }
开发者ID:sunblade,项目名称:core,代码行数:52,代码来源:cache.php

示例14: testGetLastInsertId

 public function testGetLastInsertId()
 {
     $qB = $this->connection->getQueryBuilder();
     try {
         $qB->getLastInsertId();
         $this->fail('getLastInsertId() should throw an exception, when being called before insert()');
     } catch (\BadMethodCallException $e) {
         $this->assertTrue(true);
     }
     $qB->insert('properties')->values(['userid' => $qB->expr()->literal('testFirstResult'), 'propertypath' => $qB->expr()->literal('testing'), 'propertyname' => $qB->expr()->literal('testing'), 'propertyvalue' => $qB->expr()->literal('testing')])->execute();
     $actual = $qB->getLastInsertId();
     $this->assertNotNull($actual);
     $this->assertInternalType('int', $actual);
     $this->assertEquals($this->connection->lastInsertId('*PREFIX*properties'), $actual);
     $qB->delete('properties')->where($qB->expr()->eq('userid', $qB->expr()->literal('testFirstResult')))->execute();
     try {
         $qB->getLastInsertId();
         $this->fail('getLastInsertId() should throw an exception, when being called after delete()');
     } catch (\BadMethodCallException $e) {
         $this->assertTrue(true);
     }
 }
开发者ID:kenwi,项目名称:core,代码行数:22,代码来源:querybuildertest.php

示例15: createSubscription

 /**
  * Creates a new subscription for a principal.
  *
  * If the creation was a success, an id must be returned that can be used to reference
  * this subscription in other methods, such as updateSubscription.
  *
  * @param string $principalUri
  * @param string $uri
  * @param array $properties
  * @return mixed
  */
 function createSubscription($principalUri, $uri, array $properties)
 {
     if (!isset($properties['{http://calendarserver.org/ns/}source'])) {
         throw new Forbidden('The {http://calendarserver.org/ns/}source property is required when creating subscriptions');
     }
     $values = ['principaluri' => $principalUri, 'uri' => $uri, 'source' => $properties['{http://calendarserver.org/ns/}source']->getHref(), 'lastmodified' => time()];
     $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments'];
     foreach ($this->subscriptionPropertyMap as $xmlName => $dbName) {
         if (array_key_exists($xmlName, $properties)) {
             $values[$dbName] = $properties[$xmlName];
             if (in_array($dbName, $propertiesBoolean)) {
                 $values[$dbName] = true;
             }
         }
     }
     $valuesToInsert = array();
     $query = $this->db->getQueryBuilder();
     foreach (array_keys($values) as $name) {
         $valuesToInsert[$name] = $query->createNamedParameter($values[$name]);
     }
     $query->insert('calendarsubscriptions')->values($valuesToInsert)->execute();
     return $this->db->lastInsertId('*PREFIX*calendarsubscriptions');
 }
开发者ID:GitHubUser4234,项目名称:core,代码行数:34,代码来源:CalDavBackend.php


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