/** * 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(); }
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(); }
/** * 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; }
/** * 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(); }
/** * 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; }
/** * 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; }
/** * 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(); }
/** * 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; }
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); }
/** * 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; }
/** * @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); }
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()); } }
/** * 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; }
/** * 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(); }
/** * 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; }
/** * Логирование действий над ресурсами сайта * * Не забываем выполнять его в рамках трансакции * В текущем методе манипуляции с базой происходят без трансакций * * @param string $actiontype insert | update | delete | view | null * @param array $data Массив данных для логирования @see таблицу pw_log * @return int | false * @todo Сделать Exception при недостатке полей в массиве данных и отсутствии в таблице полей logid и creatorid * @todo Подумать о целесообразности проверки наличия полей logid и creatorid */ public function setLog($actiontype, $data) { if (!isset($this->_usersession->UserData)) { return false; } $data += array('actiondate' => time(), 'userid' => $this->_usersession->UserData['userid'], 'actiontype' => $actiontype, 'mvcid' => isset($this->_params['mvcinfo']) ? (int) $this->_params['mvcinfo']['resourceid'] : 0); if ($this->_db->insert('pw_log', $data)) { $logdata = array('logid' => $logid = $this->_db->lastInsertId()); if ($actiontype == 'insert') { $logdata['creatorid'] = $data['userid']; } $logdata = $this->getFilteredValuesByTableCols($data['tablename'], $logdata); if (!empty($logdata)) { $this->_db->update($data['tablename'], $logdata, $data['fieldname'] . '=' . (int) $data['identity']); } return $logid; } return false; }
/** * Creates new entry * * @param Tinebase_Record_Interface $_record * @return Tinebase_Record_Interface * @throws Tinebase_Exception_InvalidArgument * @throws Tinebase_Exception_UnexpectedValue * * @todo remove autoincremental ids later */ public function create(Tinebase_Record_Interface $_record) { $identifier = $_record->getIdProperty(); $primaryKey = $this->_getPrimaryKey($this->_tablePrefix . $this->_tableName); 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); } // set uid if record has hash id and id is empty if ($this->_hasHashId() && empty($_record->{$identifier})) { $newId = $_record->generateUID(); $_record->setId($newId); } $recordArray = $this->_recordToRawData($_record); // unset id if autoincrement & still empty if (empty($_record->{$identifier}) || $_record->{$identifier} == 'NULL') { unset($recordArray['id']); } $recordArray = array_intersect_key($recordArray, $this->_schema); $this->_prepareData($recordArray); $this->_db->insert($this->_tablePrefix . $this->_tableName, $recordArray); if (!$this->_hasHashId()) { $newId = $this->_db->lastInsertId($this->getTablePrefix() . $this->getTableName(), $primaryKey); if (!$newId && isset($_record[$identifier])) { $newId = $_record[$identifier]; } } // if we insert a record without an id, we need to get back one if (empty($_record->{$identifier}) && $newId == 0) { throw new Tinebase_Exception_UnexpectedValue("Returned record id is 0."); } // if the record had no id set, set the id now if ($_record->{$identifier} == NULL || $_record->{$identifier} == 'NULL') { $_record->{$identifier} = $newId; } // 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); return $result; }
/** * Inserts a new row. * * Columns must be in underscore format. * * @param array $data Column-value pairs. * @param string $where An SQL WHERE clause. * @return int The last insert ID. */ public function insert(&$data) { $this->_db->insert($this->_name, $data); return $this->_db->lastInsertId($this->_name, $this->_primary); }
/** * Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column. * * As a convention, on RDBMS brands that support sequences * (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence * from the arguments and returns the last id generated by that sequence. * On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method * returns the last value generated for such a column, and the table name * argument is disregarded. * * @param string $tableName (optional) Name of table. * @param string $primaryKey (optional) Name of primary key column. * @return string */ public function lastInsertId($tableName = null, $primaryKey = null) { return $this->_adapter->lastInsertId($tableName, $primaryKey); }
/** * Inserts a new row. * * @param array $data Column-value pairs. * @return mixed The primary key of the row inserted. */ public function insert($data) { $this->_adapter->insert($this->_tableName, $data); $id = $this->_adapter->lastInsertId(); return $id; }
/** * Internal save handler. */ protected function _insert() { foreach ($this->_getTableList() as $tableName) { $this->_db->insert($tableName, $this->_newData[$tableName]); $this->_setAutoIncrementValue($this->_db->lastInsertId(), $tableName, true); } }
/** * Update a group of events with a common parent id */ private function _updateSingleChangedEventGroup($events) { $parent = $this->_db->select()->from('calendar')->where('id = ?', $events[0]['parent_id'])->query()->fetch(); $start = new Datetime($parent['start_datetime']); $duration = $start->diff(new Datetime($parent['end_datetime'])); $helper = new Calendar2_Helper_Rrule($start, $duration, $parent['rrule']); $last = new Datetime($events[count($events) - 1]['end_datetime']); $occurrences = $helper->getDatesInPeriod($start, $last); $deleted = array(); $added = array(); while (!empty($events) && $events[0]['start_datetime'] == $parent['start_datetime']) { array_shift($events); } $addedTimes = array(); $regularTimes = array(); foreach ($events as $e) { // At this point we throw away confirmation information, mostly because I'm too tired and it's too // complicated to retrieve them. if ($e['participant_id'] != $parent['owner_id']) { continue; } if (empty($occurrences)) { $addedTimes[] = $e['start_datetime']; $added[] = $e; continue; } $cmp = $this->_compareDatetimeWithEvent($occurrences[0], $e); if ($cmp < 0) { // occurrence is before $deleted[] = array_shift($occurrences); } else { if ($cmp === 0) { $regularTimes[] = array_shift($occurrences); if ($this->_eventDataDiffers($parent, $e)) { $addedTimes[] = $e['start_datetime']; $deleted[] = new Datetime($e['start_datetime']); $added[] = $e; } } else { // event is before occurrence $added[] = $e; } } } $addedEventsParticipants = array(); foreach ($events as $e) { if ($e['participant_id'] == $parent['owner_id']) { continue; } if (in_array($e['start_datetime'], $addedTimes)) { if (!array_key_exists($e['start_datetime'], $addedEventsParticipants)) { $addedEventsParticipants[$e['start_datetime']] = array(); } $addedEventsParticipants[$e['start_datetime']][] = array('id' => $e['participant_id'], 'status' => $e['status']); } else { if (!in_array($e['start_datetime'], $regularTimes)) { // This event doesn't really belong here. We just create a new one for the user independent of $parent. $uid = Phprojekt::generateUniqueIdentifier(); $this->_db->insert('calendar2', array('project_id' => $e['project_id'], 'summary' => $e['title'], 'description' => $e['notes'], 'location' => $e['place'], 'comments' => "", 'start' => $e['start_datetime'], 'last_end' => $e['end_datetime'], 'end' => $e['end_datetime'], 'owner_id' => $e['participant_id'], 'rrule' => '', 'visibility' => $e['visibility'] + 1, 'uri' => $uid, 'uid' => $uid)); $newCalendarId = $this->_db->lastInsertId(); $this->_db->insert('calendar2_user_relation', array('calendar2_id' => $newCalendarId, 'user_id' => $e['participant_id'], 'confirmation_status' => $e['status'])); } } } if (!empty($deleted)) { $this->_deletedOccurrences($parent, $deleted); } if (!empty($added)) { $this->_addedOccurrences($parent, $added, $addedEventsParticipants); } }
/** * Inserts a new row. * * @param array $data Column-value pairs. * @return mixed The primary key of the row inserted. */ public function insert(array $data) { $this->_setupPrimaryKey(); /** * 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); $pkSuppliedBySequence = true; } /** * If the primary key can be generated automatically, and no value was * specified in the user-supplied data, then omit it from the tuple. * * Note: this checks for sensible values in the supplied primary key * position of the data. The following values are considered empty: * null, false, true, '', array() */ if (!isset($pkSuppliedBySequence) && array_key_exists($pkIdentity, $data)) { if ($data[$pkIdentity] === null || $data[$pkIdentity] === '' || is_bool($data[$pkIdentity]) || is_array($data[$pkIdentity]) && empty($data[$pkIdentity])) { // empty array 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) { reset($pkData); return current($pkData); } return $pkData; }
public function lastInsertId() { return $this->_connection->lastInsertId(); }