php:致命错误:调用未定义的函数sqlsrv_connect()

时间:2016-03-16 12:32:14

标签: php sql-server xampp

我有一个大问题我希望在这里解决这个问题 我尝试使用:

连接到Sql Server 2008 R2
  1. php 5.6.11
  2. Xampp 5.6.3
  3. Sql Server 2008 r2
  4. 为PHP使用sql server驱动程序(php_pdo_sqlsrv_56_ts.dl& php_sqlsrv_56_ts.dll)
  5. 我尝试连接的代码是:

     $serverName = "Mahmoud-HP\SQL2008R2"; //serverName\instanceName
        $connectionInfo = array( "Database"=>"HR16", "UID"=>"Mahmoud", "PWD"=>"123" , "MultipleActiveResultSets" => false);
        $conn = sqlsrv_connect( $serverName, $connectionInfo);
    
        if( $conn ) {
             echo "Connection established.<br />";
        }else{
             echo "Connection could not be established.<br />";
             die( print_r( sqlsrv_errors(), true));
        }
    

    但在运行页面时,此消息将发送给我

      

    致命错误:在C:\ xampp \ htdocs \ testsqlserver \ index.php上调用未定义函数sqlsrv_connect()

    这个问题的解决方案是什么

1 个答案:

答案 0 :(得分:1)

你必须使用php的SQL Server本机驱动程序。

从这里下载:

https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=20098

示例代码:

$serverName = "tcp:ServerID.database.windows.net, 1433";

$connectionOptions = array("Database" => "DatabaseName", 

                           "UID" => "Username@ServerID",

                           "PWD" => "password");

$conn = sqlsrv_connect($serverName, $connectionOptions);



if($conn === false)

{

    die(print_r(sqlsrv_errors(), true));

}

修改

确保您加载列出的两个dll:

extension=php_sqlsrv_56_ts.dll

extension=php_pdo_sqlsrv_56_ts.dll