3
3
3ds2010-10-12 12:39:36
PHP
3ds, 2010-10-12 12:39:36

Zend Framework, MSSQL 2008 R2, PDO -> insert lastInsertId?

How to get lastInsertId if doing in zend

$model-&gt;insert(array(<br/>
 'data1' =&gt; $data1,<br/>
 'data2' =&gt; $data2,<br/>
));<br/>

$model->lastInserId(); - does not work…

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lafayette, 2010-10-12
@lafayette

zend-framework-community.634137.n4.nabble.com/mssql-pdo-lastInsertID-with-a-stored-procedure-td672685.html

P
pietrovich, 2010-10-12
@pietrovich

php.net/manual/en/pdo.lastinsertid.php

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.

after such a notice in the documentation, the first thing that comes to mind is the need to take care of “your own, reliable” tool.
as an option - a comment from php.net/manual/en/pdo.lastinsertid.php - why not a workaround?
alternatively you can use
select IDENT_CURRENT('tableName');
or
select SCOPE_IDENTITY();
after a successful insert.
and, of course, don't forget about sessions and scope to get exactly what you need ( msdn.microsoft.com/en-us/library/ms175098.aspx )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question