PHP中Microsoft SQL Server的连接参数

时间:2019-03-21 20:06:35

标签: php sql sql-server

我正在尝试使用PHP连接到Microsoft SQL Server

要在sql Management Studio中使用镜像数据库,我在“其他连接参数”标签中使用“ ApplicationIntent = ReadOnly”。

如何在php中设置此参数?

我如何不使用参数进行连接的示例:

$serverName = "server, port";
$connectionInfo = array( "Database"=>"my_db");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

1 个答案:

答案 0 :(得分:0)

您可以将其作为选项之一传递,如下所示:

sqlsrv_connect($serverName, ['ApplicationIntent' => 'ReadOnly']);

或者您的情况:

$serverName = "server, port"; 
$connectionInfo = array('Database' => 'my_db', 'ApplicationIntent' => 'ReadOnly'); 
$conn = sqlsrv_connect( $serverName, $connectionInfo);

另请参阅php docs for sqlsrv_connect()