Reputation: 1926
does this code gives me the last inserted id of the record, even on a heavy load page?
db = Zend_Db_Table::getDefaultAdapter();
$db->insert($this->_name, $fields_values);
$idAddress = $db->lastInsertId($this->_name);
Regards Andrea
Upvotes: 2
Views: 2109
Reputation: 787
public function saveData(array $data) {
$this->_setName('user');
// this will return all field name for user table in $field variable
$fields = $this->info($this->getConstCol());
// By this foreach loop we will set data in $data array
foreach ($data as $field => $value)
{
if (!in_array($field, $fields))
{
unset($data[$field]);
}
}
// It will call insert function of (Zend_Db_Table_Abstract Parent of Zend_Db_Table)
// It will return $pkData which is primary key for user table
return $this->insert($data); // It will return last insert ID
}
Upvotes: 0
Reputation: 4858
i am using this...
db = Zend_Db_Table::getDefaultAdapter();
$lastInsertId = $db->insert($this->_name, $fields_values);
Upvotes: 2
Reputation: 12420
The Zend_Db_Adapter_Abstract::lastInsertId()
method is a proxy to PDO::lastInsertId()
. According to the documentation:
PDO::lastInsertId — Returns the ID of the last inserted row or sequence value
Note:
This method may not return a meaningful or consistent result across different PDO drivers, because the underlying database may not even support the notion of auto-increment fields or sequences.
Now you know. Use it as your own risk!
Upvotes: 1