Possible Duplicate:
SQL: How to get the id of values I just INSERTed?
For PHP, What’s equivalent of mysql_insert_id() for sql server 2012?
sqlsrv_insert_id() does not seem to exist.
Say this is the code
if ($result) {
// get user details
$uid = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM users WHERE uid = $uid");
// return user details
return mysql_fetch_array($result);
} else {
return false;
}
for mysql,
how should I do it for sql server?
Check this out: https://www.php.net/manual/en/book.mssql.php
Over there at the comments you have the php syntax at the comments:
function mssql_insert_id() { $id = 0; $res = mssql_query("SELECT @@identity AS id"); if ($row = mssql_fetch_array($res, MSSQL_ASSOC)) { $id = $row["id"]; } return $id; }