我有一个大问题我希望在这里解决这个问题 我尝试使用:
连接到Sql Server 2008 R2我尝试连接的代码是:
$serverName = "Mahmoud-HP\SQL2008R2"; //serverName\instanceName
$connectionInfo = array( "Database"=>"HR16", "UID"=>"Mahmoud", "PWD"=>"123" , "MultipleActiveResultSets" => false);
$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));
}
但在运行页面时,此消息将发送给我
致命错误:在C:\ xampp \ htdocs \ testsqlserver \ index.php上调用未定义函数sqlsrv_connect()
这个问题的解决方案是什么
答案 0 :(得分:1)
你必须使用php的SQL Server本机驱动程序。
从这里下载:
https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=20098
示例代码:
$serverName = "tcp:ServerID.database.windows.net, 1433";
$connectionOptions = array("Database" => "DatabaseName",
"UID" => "Username@ServerID",
"PWD" => "password");
$conn = sqlsrv_connect($serverName, $connectionOptions);
if($conn === false)
{
die(print_r(sqlsrv_errors(), true));
}
修改
确保您加载列出的两个dll:
extension=php_sqlsrv_56_ts.dll
和
extension=php_pdo_sqlsrv_56_ts.dll