php - 相当于 ms sql server 的 mysql_insert_id()

标签 php sql-server sql-server-2012

<分区>

Possible Duplicate:
SQL: How to get the id of values I just INSERTed?

对于 PHP,对于 sql server 2012,mysql_insert_id() 的等效项是什么?

sqlsrv_insert_id() 好像不存在。

说这是代码

  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;
        }

对于mysql, 我应该如何为 sql server 做这件事?

最佳答案

检查一下:http://fr2.php.net/manual/en/book.mssql.php 在评论那里,你在评论中有 php 语法:


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; 
} 

关于php - 相当于 ms sql server 的 mysql_insert_id(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12880567/

相关文章:

php - Laravel 5 + MongoDB

SQL Server 列的大小差异

SQL Server 数据透视查询替代或优化

php - Symfony 3从 Controller 内的表单类更改提交标签

php - 路由到子文件夹中的 Controller 在 Laravel 4 中不起作用

php - 按喜欢对 Facebook 评论插件进行排序

sql-server - 如何在SSIS数据流中捕获多个错误列

asp.net - Azure API应用程序与移动应用程序与Web应用程序

c# - 将 .NET 和 SQL Server 数据库应用程序迁移到新计算机

c# - 将 Binary(16) 转换为 int,在 C# 中结果相同