Re: pdo::lastInsertId() error with SQL Server

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



use scope_identity() if you're using MS SQL Server 2000 or newer.

scope_identity slects the last id within your current scope (The last record
you entered in your current session)


On 3/29/07, Sady Marcos <smarcos@xxxxxxxxxxxxxxx> wrote:


hey..
I am not obtaining use the function pdo::lastInsertId() with sql
My code:

$db = new PDO("mssql:host=host;dbname=database","user","password");
$sql = "INSERT INTO users(name,status) VALUES('username','1)";
$db->query($sql);
$db->lastInsertId();

Error:

SQLSTATE[IM001]: Driver does not support this function: driver does not
support lastInsertId()

This is true?
The only way would be executing query "SELECT @@IDENTITY as Id" ?

Thanks for help

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux