0

What is mssql function that have similar with mysql_db_query()?

and what about mysql_insert_id()?

1
  • ops, sorry for not inform about language, it's php. Commented Jan 5, 2011 at 15:34

3 Answers 3

1

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; 
} 
?>
Sign up to request clarification or add additional context in comments.

2 Comments

For mysql, it has mysql_query and mysql_db_query, but for mssql only has mssql_query. mssql_query same with mysql_query but not with mysql_db_query.
@Hafizul 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().
0

I think the closest you will come to this in T-SQL is the following:

Use <MyDatabase>
Exec ('Select <ColumnList> From <SomeTable>')

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.