What is mssql function that have similar with mysql_db_query()?
and what about mysql_insert_id()?
Look at the PHP Mssql documentation. The functions you're looking for are mssql_query() and the following:
<?php
function mssql_insert_id() {
$id = 0;
$res = mssql_query("SELECT @@identity AS id");
if ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
$id = $row["id"];
}
return $id;
}
?>
mysql_db_query() is deprecated, all it does is (effectively) mysql_select_db() followed by mysql_query(). You can easily emulate this behaviour with mssql_select_db() and mssql_query().In MSSQL, you can use the SCOPE_IDENTITY() function to get the last ID created by the given connection, in the same scope. Put them both together so you get the ID back just after row creation.
INSERT INTO myTable (field1,field2) VALUES(val1,val2); SELECT SCOPE_IDENTITY() AS myId;
Note, you could also use @@IDENTITY, but that returns the last ID created, regardless of scope, so if you inserted a new row, and a trigger/stored procedure fired and inserted something into another table, @@IDENTITY would return that ID.