我需要在PHP中连接到MS SQL SERVER 2008 R2。我遵循了某些教程,但没有解决我的问题。我使用了以下代码:
$serverName = "DARSHAN'SQLEXPRESS"; //serverName'instanceName, portNumber (default is 1433)
$connectionInfo = array( "Database"=>"trail", "UID"=>"**", "PWD"=>"******");
$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));
}
此代码与我的服务器连接,但是当我删除 UID 和 PWD 参数时,连接没有连接。我想使用窗口身份验证模式。请帮帮我。
<?php
$serverName = "DARSHAN'SQLEXPRESS";
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"trail");
$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));
}
?>
源:
http://php.net/sqlsrv_connect