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


PHP Zend_Db_Adapter_Abstract::lastInsertId方法代码示例

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


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

示例1: run

 /**
  * Trigger an import run
  *
  * @return int Last import run ID
  */
 public function run()
 {
     if ($this->providesChanges() && !$this->rowsetExists()) {
         $this->storeRowset();
     }
     $this->db->insert('import_run', array('source_id' => $this->source->id, 'rowset_checksum' => $this->rowsetChecksum(), 'start_time' => date('Y-m-d H:i:s'), 'succeeded' => 'y'));
     return $this->db->lastInsertId();
 }
开发者ID:dgoeger,项目名称:icingadirector,代码行数:13,代码来源:Import.php

示例2: save

 public function save(Mage_Admin_Model_Permissions_Roles $role)
 {
     if ($role->getPid() > 0) {
         $row = $this->load($role->getPid());
     } else {
         $row = array('tree_level' => 0);
     }
     if ($role->getId()) {
         $this->_write->update($this->_roleTable, array('parent_id' => $role->getPid(), 'tree_level' => $row['tree_level'] + 1, 'role_name' => $role->getName()), "role_id = {$role->getId()}");
     } else {
         $this->_write->insert($this->_roleTable, array('parent_id' => $role->getPid(), 'tree_level' => $row['tree_level'] + 1, 'role_name' => $role->getName(), 'role_type' => $role->getRoleType()));
         $role->setId($this->_write->lastInsertId());
     }
     $this->_updateRoleUsersAcl($role);
     return $role->getId();
 }
开发者ID:arslbbt,项目名称:mangentovies,代码行数:16,代码来源:Roles.php

示例3: createObject

 /**
  * Create a row for a given object.
  * forwards the call to the underlying insert() method.
  *
  * @param mixed $object
  * @param boolean $assignId Whether to assign the generated ID back as
  *                     the object's ID.
  */
 public function createObject($object, $assignId = true)
 {
     $table = strtolower(get_class($object));
     // set some properties
     $refObj = new ReflectionObject($object);
     if ($refObj->hasProperty('created') && !$object->created) {
         $object->created = date('Y-m-d H:i:s', time());
     }
     if ($refObj->hasProperty('creator') && !$object->creator) {
         $object->creator = za()->getUser()->getUsername();
     }
     $row = $this->getRowFrom($object);
     try {
         $this->triggerObjectEvent($object, 'create');
         $return = $this->insert($table, $row);
         if ($return && $assignId) {
             // Return the last insert ID
             $object->id = $this->proxied->lastInsertId($table, 'id');
             $this->triggerObjectEvent($object, 'created');
             return $object->id;
         }
         $this->triggerObjectEvent($object, 'created');
         return $return;
     } catch (Exception $e) {
         error_log("Caught: " . $e->getMessage());
         error_log($e->getTraceAsString());
         throw $e;
     }
     return false;
 }
开发者ID:nyeholt,项目名称:relapse,代码行数:38,代码来源:DbService.php

示例4: insert

 /**
  * Every query ends up looking like: 
  * INSERT INTO table (field, field2, field3, ...) VALUES (?, ?, ?, ...) 
  * ON DUPLICATE KEY UPDATE field = ?, field2 = ?, ...
  *
  * Note on portability: ON DUPLICATE KEY UPDATE is a MySQL extension.  
  * The advantage to using this is that it doesn't care whether a row exists already.
  * Basically it combines what would be insert() and update() methods in other 
  * ORMs into a single method
  * 
  * @param string $table Table model class name.
  * @param array $values Rows to insert (or update).
  * @return integer The ID for the row that got inserted (or updated).
  */
 public function insert($table, array $values = array())
 {
     if (empty($values)) {
         return false;
     }
     $table = $this->getTableName($table);
     // Column names are specified as array keys.
     $cols = array_keys($values);
     // Build the statement.
     $query = "INSERT INTO `{$table}` (`" . implode('`, `', $cols) . "`) VALUES (";
     $query .= implode(', ', array_fill(0, count($values), '?')) . ')';
     $insertParams = array_values($values);
     $updateQuery = array();
     $updateParams = $values;
     foreach ($cols as $col) {
         switch ($col) {
             case 'id':
                 $updateQuery[] = '`id` = LAST_INSERT_ID(`id`)';
                 // Since we're not actually using the 'id' param in the
                 // UPDATE clause, remove it
                 unset($updateParams['id']);
                 break;
             default:
                 $updateQuery[] = "`{$col}` = ?";
                 break;
         }
     }
     // Build the update of duplicate key clause.
     $query .= ' ON DUPLICATE KEY UPDATE ' . implode(', ', $updateQuery);
     // Prepare and execute the statement.
     $params = array_merge($insertParams, array_values($updateParams));
     $this->query($query, $params);
     return (int) $this->_adapter->lastInsertId();
 }
开发者ID:lchen01,项目名称:STEdwards,代码行数:48,代码来源:Db.php

示例5: insert

 /**
  * Inserts a new row.
  *
  * @param  array  $data  Column-value pairs.
  * @return mixed         The primary key of the row inserted.
  */
 public function insert(array $data)
 {
     /**
      * Zend_Db_Table assumes that if you have a compound primary key
      * and one of the columns in the key uses a sequence,
      * it's the _first_ column in the compound key.
      */
     $primary = (array) $this->_primary;
     $pkIdentity = $primary[(int) $this->_identity];
     /**
      * If this table uses a database sequence object and the data does not
      * specify a value, then get the next ID from the sequence and add it
      * to the row.  We assume that only the first column in a compound
      * primary key takes a value from a sequence.
      */
     if (is_string($this->_sequence) && !isset($data[$pkIdentity])) {
         $data[$pkIdentity] = $this->_db->nextSequenceId($this->_sequence);
     }
     /**
      * If the primary key can be generated automatically, and no value was
      * specified in the user-supplied data, then omit it from the tuple.
      */
     if (array_key_exists($pkIdentity, $data) && $data[$pkIdentity] === null) {
         unset($data[$pkIdentity]);
     }
     /**
      * INSERT the new row.
      */
     $tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
     $this->_db->insert($tableSpec, $data);
     /**
      * Fetch the most recent ID generated by an auto-increment
      * or IDENTITY column, unless the user has specified a value,
      * overriding the auto-increment mechanism.
      */
     if ($this->_sequence === true && !isset($data[$pkIdentity])) {
         $data[$pkIdentity] = $this->_db->lastInsertId();
     }
     /**
      * Return the primary key value if the PK is a single column,
      * else return an associative array of the PK column/value pairs.
      */
     $pkData = array_intersect_key($data, array_flip($primary));
     if (count($primary) == 1) {
         return current($pkData);
     } else {
         return $pkData;
     }
     /**
      * The last case:  the user did not specify a value for the primary
      * key, nor is this table class declared to use an auto-increment key.
      * Since the insert did not fail, we can assume this is one of the edge
      * cases, which may include:
      * - the table has no primary key defined;
      * - the database table uses a trigger to set a primary key value;
      * - the RDBMS permits primary keys to be NULL or have a value set
      *   to the column's DEFAULT
      */
     return null;
 }
开发者ID:sluther,项目名称:portsensor,代码行数:66,代码来源:Abstract.php

示例6: insert

 /**
  * Inserts a new row.
  *
  * @param  array  $data  Column-value pairs.
  * @return mixed         The primary key of the row inserted.
  */
 public function insert(array $data)
 {
     /**
      * Zend_Db_Table assumes that if you have a compound primary key
      * and one of the columns in the key uses a sequence,
      * it's the _first_ column in the compound key.
      */
     $primary = (array) $this->_primary;
     $pkIdentity = $primary[(int) $this->_identity];
     /**
      * If this table uses a database sequence object and the data does not
      * specify a value, then get the next ID from the sequence and add it
      * to the row.  We assume that only the first column in a compound
      * primary key takes a value from a sequence.
      */
     if (is_string($this->_sequence) && !isset($data[$pkIdentity])) {
         $data[$pkIdentity] = $this->_db->nextSequenceId($this->_sequence);
     }
     /**
      * If the primary key can be generated automatically, and no value was
      * specified in the user-supplied data, then omit it from the tuple.
      */
     if (array_key_exists($pkIdentity, $data) && $data[$pkIdentity] === null) {
         unset($data[$pkIdentity]);
     }
     /**
      * Run pre-INSERT logic
      */
     if ($this->notify('preInsert', $this, $data) === false) {
         return null;
     }
     /**
      * INSERT the new row.
      */
     $tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
     $this->_db->insert($tableSpec, $data);
     /**
      * Fetch the most recent ID generated by an auto-increment
      * or IDENTITY column, unless the user has specified a value,
      * overriding the auto-increment mechanism.
      */
     if ($this->_sequence === true && !isset($data[$pkIdentity])) {
         $data[$pkIdentity] = $this->_db->lastInsertId();
     }
     /**
      * Run post-INSERT logic
      */
     $this->notify('postInsert', $this, $data);
     /**
      * Return the primary key value if the PK is a single column,
      * else return an associative array of the PK column/value pairs.
      */
     $pkData = array_intersect_key($data, array_flip($primary));
     if (count($primary) == 1) {
         reset($pkData);
         return current($pkData);
     }
     return $pkData;
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:65,代码来源:Abstract.php

示例7: insert

 /**
  * Inserts a new row.
  *
  * @param  array  $data  Column-value pairs.
  * @param  string $where An SQL WHERE clause.
  * @return integer       The last insert ID.
  */
 public function insert(array $data)
 {
     $this->_db->insert($this->_name, $data);
     // @todo handle tables that have no auto-generated key.
     // @todo handle tables that use a named sequence instead
     // of an implict auto-generated key.
     return $this->_db->lastInsertId();
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:15,代码来源:Abstract.php

示例8: _insert

 /**
  * Callback function on create new row.
  */
 protected function _insert(Days_Db_Row $row)
 {
     $data = $row->toArray();
     $this->_db->insert($this->_name, $data);
     $id = $this->_db->lastInsertId();
     $row->id = $id;
     return $id;
 }
开发者ID:laiello,项目名称:phpdays,代码行数:11,代码来源:Table.php

示例9: testTableInsert

 public function testTableInsert()
 {
     list($dbTable, $table, $id) = $this->getInstanceOfDbTable();
     $row = array('title' => 'News Item 3', 'subtitle' => 'Sub title 3', 'body' => 'This is body 1', 'date_created' => '2006-05-03 13:13:13');
     $insertResult = $dbTable->insert($row);
     $last_insert_id = $this->_db->lastInsertId();
     $this->assertEquals($insertResult, (string) $last_insert_id);
     $this->assertEquals(3, (string) $last_insert_id);
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:9,代码来源:Common.php

示例10: insert

 /**
  * Inserts a new row.
  *
  * @param  array  $data  Column-value pairs.
  * @return mixed         The primary key of the row inserted.
  */
 public function insert(array $data)
 {
     /**
      * Zend_Db_Table assumes that if you have a compound primary key
      * and one of the columns in the key uses a sequence,
      * it's the _first_ column in the compound key.
      */
     $primary = (array) $this->_primary;
     $pkIdentity = $primary[(int) $this->_identity];
     /**
      * If this table uses a database sequence object and the data does not
      * specify a value, then get the next ID from the sequence and add it
      * to the row.  We assume that only the first column in a compound
      * primary key takes a value from a sequence.
      */
     if (is_string($this->_sequence) && !isset($data[$pkIdentity])) {
         $data[$pkIdentity] = $this->_db->nextSequenceId($this->_sequence);
     }
     /**
      * INSERT the new row.
      */
     $this->_db->insert($this->_name, $data);
     if (isset($data[$pkIdentity])) {
         /**
          * Return the primary key value or array of values(s) if the
          * primary key is compound.  This handles the case of natural keys
          * and sequence-driven keys.  This also covers the case of
          * auto-increment keys when the user specifies a value, thus
          * overriding the auto-increment logic.
          */
         $pkData = array_intersect_key($data, array_flip($primary));
         if (count($primary) == 1) {
             return current($pkData);
         } else {
             return $pkData;
         }
     }
     if ($this->_sequence === true) {
         /**
          * Return the most recent ID generated by an auto-increment
          * or IDENTITY column.
          */
         return $this->_db->lastInsertId();
     }
     /**
      * The last case:  the user did not specify a value for the primary
      * key, nor is this table class declared to use an auto-increment key.
      * Since the insert did not fail, we can assume this is one of the edge
      * cases, which may include:
      * - the table has no primary key defined;
      * - the database table uses a trigger to set a primary key value;
      * - the RDBMS permits primary keys to be NULL or have a value set
      *   to the column's DEFAULT
      */
     return null;
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:62,代码来源:Abstract.php

示例11: appendChild

 /**
  * @param Node $data
  * @param Node $parentNode
  * @param Node $prevNode
  * @return Node
  */
 public function appendChild($data, $parentNode, $prevNode = null)
 {
     $orderSelect = $this->_conn->select();
     $orderSelect->from($this->_table, new \Zend_Db_Expr('MAX(' . $this->_conn->quoteIdentifier($this->_orderField) . ')'))->where($this->_conn->quoteIdentifier($this->_parentField) . '=' . $parentNode->getId());
     $order = $this->_conn->fetchOne($orderSelect);
     $data[$this->_parentField] = $parentNode->getId();
     $data[$this->_levelField] = $parentNode->getData($this->_levelField) + 1;
     $data[$this->_orderField] = $order + 1;
     $this->_conn->insert($this->_table, $data);
     $data[$this->_idField] = $this->_conn->lastInsertId();
     return parent::appendChild($data, $parentNode, $prevNode);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:18,代码来源:Db.php

示例12: save

 public function save(Mage_Review_Model_Review $review)
 {
     $this->_write->beginTransaction();
     try {
         if ($review->getId()) {
             $data = $this->_prepareUpdateData($review);
             $condition = $this->_write->quoteInto('review_id = ?', $review->getId());
             $this->_write->update($this->_reviewTable, $data['base'], $condition);
             $this->_write->update($this->_reviewDetailTable, $data['detail'], $condition);
         } else {
             $data = $this->_prepareInsertData($review);
             $data['base']['created_at'] = now();
             $this->_write->insert($this->_reviewTable, $data['base']);
             $review->setId($this->_write->lastInsertId());
             $data['detail']['review_id'] = $review->getId();
             $this->_write->insert($this->_reviewDetailTable, $data['detail']);
         }
         if (isset($data['stores'])) {
             $condition = $this->_write->quoteInto('review_id = ?', $review->getId());
             $this->_write->delete($this->_reviewStoreTable, $condition);
             $insertedStoreIds = array();
             foreach ($data['stores'] as $storeId) {
                 if (in_array($storeId, $insertedStoreIds)) {
                     continue;
                 }
                 $insertedStoreIds[] = $storeId;
                 $storeInsert = array();
                 $storeInsert['store_id'] = $storeId;
                 $storeInsert['review_id'] = $review->getId();
                 $this->_write->insert($this->_reviewStoreTable, $storeInsert);
             }
         }
         $this->_write->commit();
     } catch (Exception $e) {
         $this->_write->rollBack();
         throw new Exception($e->getMessage());
     }
 }
开发者ID:arslbbt,项目名称:mangentovies,代码行数:38,代码来源:Review.php

示例13: create

 /**
  * Creates new entry
  *
  * @param   Tinebase_Record_Interface $_record
  * @return Tinebase_Record_Interface
  * @throws Exception
  * @todo    remove autoincremental ids later
  */
 public function create(Tinebase_Record_Interface $_record)
 {
     $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction($this->_db);
     try {
         $identifier = $_record->getIdProperty();
         if (!$_record instanceof $this->_modelName) {
             throw new Tinebase_Exception_InvalidArgument('invalid model type: $_record is instance of "' . get_class($_record) . '". but should be instance of ' . $this->_modelName);
         }
         /** @var Tinebase_Record_Interface $_record */
         // set uid if record has hash id and id is empty
         if (empty($_record->{$identifier}) && $this->_hasHashId()) {
             $_record->setId(Tinebase_Record_Abstract::generateUID());
         }
         $recordArray = $this->_recordToRawData($_record);
         // unset id if autoincrement & still empty
         if ($this->_hasAutoIncrementId() || $_record->{$identifier} == 'NULL') {
             unset($recordArray['id']);
         }
         $recordArray = array_intersect_key($recordArray, $this->getSchema());
         $this->_prepareData($recordArray);
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " Prepared data for INSERT: " . print_r($recordArray, true));
         }
         $this->_db->insert($this->_tablePrefix . $this->_tableName, $recordArray);
         if ($this->_hasAutoIncrementId()) {
             $newId = $this->_db->lastInsertId($this->getTablePrefix() . $this->getTableName(), $identifier);
             if (!$newId) {
                 throw new Tinebase_Exception_UnexpectedValue("New record auto increment id is empty");
             }
             $_record->setId($newId);
         }
         // if we insert a record without an id, we need to get back one
         if (empty($_record->{$identifier})) {
             throw new Tinebase_Exception_UnexpectedValue("Returned record id is empty.");
         }
         // add custom fields
         if ($_record->has('customfields') && !empty($_record->customfields)) {
             Tinebase_CustomField::getInstance()->saveRecordCustomFields($_record);
         }
         $this->_updateForeignKeys('create', $_record);
         $result = $this->get($_record->{$identifier});
         $this->_inspectAfterCreate($result, $_record);
         Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId);
     } catch (Exception $e) {
         Tinebase_TransactionManager::getInstance()->rollBack();
         throw $e;
     }
     return $result;
 }
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:57,代码来源:Abstract.php

示例14: clear

 /**
  * Clear table and add root element
  *
  * @param array $data
  * @return string
  */
 public function clear($data = [])
 {
     // clearing table
     $this->_db->query('TRUNCATE ' . $this->_table);
     // prepare data for root element
     $data[$this->_pid] = 0;
     $data[$this->_left] = 1;
     $data[$this->_right] = 2;
     $data[$this->_level] = 0;
     try {
         $this->_db->insert($this->_table, $data);
     } catch (\PDOException $e) {
         echo $e->getMessage();
     }
     return $this->_db->lastInsertId();
 }
开发者ID:vasiljok,项目名称:magento2,代码行数:22,代码来源:Tree.php

示例15: save

 /**
  * Save subscriber info from it model.
  *
  * @param  Mage_Newsletter_Model_Subscriber $subscriber
  * @return Mage_Newsletter_Model_Subscriber
  */
 public function save(Mage_Newsletter_Model_Subscriber $subscriber)
 {
     $this->_write->beginTransaction();
     try {
         $data = $this->_prepareSave($subscriber);
         if ($subscriber->getId()) {
             $this->_write->update($this->_subscriberTable, $data, $this->_write->quoteInto('subscriber_id=?', $subscriber->getId()));
         } else {
             $this->_write->insert($this->_subscriberTable, $data);
             $subscriber->setId($this->_write->lastInsertId($this->_subscriberTable));
         }
         $this->_write->commit();
     } catch (Exception $e) {
         $this->_write->rollBack();
         Mage::throwException(Mage::helper('newsletter')->__('Cannot save your subscription: %s', $e->getMessage()));
     }
     return $subscriber;
 }
开发者ID:arslbbt,项目名称:mangentovies,代码行数:24,代码来源:Subscriber.php


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