简体   繁体   English

PHP中Microsoft SQL Server的连接参数

[英]Connection parameters for Microsoft SQL Server in PHP

I'm trying to connect to Microsoft SQL Server with PHP 我正在尝试使用PHP连接到Microsoft SQL Server

To work with a mirrored database in the sql management studio I use "ApplicationIntent=ReadOnly" in the "Additional Connection Parameters" label. 要在sql管理工作室中使用镜像数据库,我在“其他连接参数”标签中使用“ApplicationIntent = ReadOnly”。

How can I set this parameter in php? 如何在php中设置此参数?

Example of how I'm connection without the parameter: 我没有参数的连接示例:

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

You can pass it as one of the options, like so: 您可以将其作为选项之一传递,如下所示:

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

Or in your case: 或者在你的情况下:

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

See also the php docs for sqlsrv_connect() . 另请参阅sqlsrv_connect()php文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM