PHP无法连接sql_srv

时间:2018-07-25 16:51:45

标签: php sql-server windows-7 xampp

PHP SQL服务器无法连接。

Array([0] => Array([0] => 08001 [SQLSTATE] => 08001 [1] => 21 [code] => 21 [2] => [Microsoft] [ODBC Driver for SQL服务器]客户端上不支持加密。[消息] => [Microsoft] [SQL Server ODBC驱动程序17]客户端上不支持加密。)[1] =>数组([0] => 08001 [SQLSTATE] = > 08001 [1] => 87 [代码] => 87 [2] => [Microsoft] [用于SQL Server的ODBC驱动程序17] SQL Server网络接口:参数不正确。[消息] => [Microsoft] [ODBC]用于SQL Server的驱动程序17 [SQL Server网络接口:参数不正确。] [2] =>数组([0] => 08001 [SQLSTATE] => 08001 [1] => 21 [代码] => 21 [2 ] => [Microsoft] [SQL Server ODBC驱动程序17]客户端无法建立连接[消息] => [Microsoft] [SQL Server的ODBC驱动程序17]客户端无法建立连接)[3] =>数组([0 ] => 08001 [SQLSTATE] => 08001 [1] => 87 [代码] => 87 [2] => [Microsoft] [用于SQL Server的ODBC驱动程序17]建立与SQL Server的连接。找不到服务器或无法访问服务器。检查实例名称是否正确以及SQL Server是否配置为允许远程连接。有关更多信息,请参见SQL Server联机丛书。 [消息] => [Microsoft] [SQL Server的ODBC驱动程序17]建立与SQL Server的连接时,发生了与网络相关或特定于实例的错误。找不到服务器或无法访问服务器。检查实例名称是否正确以及SQL Server是否配置为允许远程连接。有关更多信息,请参见SQL Server联机丛书。 )

$connectionInfo = array( "Database"=>"Service");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
echo "<pre>";
print_r($conn);
if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}

$connectionInfo = array( "Database"=>"Service"); $conn = sqlsrv_connect( $serverName, $connectionInfo); echo "<pre>"; print_r($conn); if( $conn ) { echo "Connection established.<br />"; }else{ echo "Connection could not be established.<br />"; die( print_r( sqlsrv_errors(), true)); }

1 个答案:

答案 0 :(得分:0)

请参阅正式的Microsoft文档:

$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd, 
"ColumnEncryption"=>"Enabled");
 $conn = sqlsrv_connect($server, $connectionInfo);

来源:https://docs.microsoft.com/en-us/sql/connect/php/using-always-encrypted-php-drivers?view=sql-server-2017