SQL Connect Via PHP


   $serverName = "172.20.90.100"; 
   // Since UID and PWD are not specified in the $connectionInfo array,
   // The connection will be attempted using Windows Authentication.
   $connectionInfo = array( "Database"=>"correctdb");
   $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));
   }    

这给了我这个错误:

致命错误:在第 23 行调用未定义的函数 sqlsrv_connect((

我想知道我应该改变什么来建立连接。

sqlsrv_connect()是嵌入在SQL服务器扩展中的php函数。该错误显示您尚未启用它。

您必须启用扩展。手册中描述了如何完成此操作。

  • 如果您尚未安装Microsoft Drivers 3.0 for PHP for SQL Server,请从此处安装。

  • 确保php.ini中有以下行:

    extension=php_pdo_sqlsrv_53_ts.dll
    extension=php_sqlsrv_53_ts.dll
    

文档: sqlsrv_connect()

最新更新