我一直在用PHP(xampp)做一个项目,需要连接到SQL Server数据库。
我已经做了一些事情,例如在文件夹中下载和安装SQLSRV30.exe
C:'xampp'php'ext
并创建一个简单的程序来确定该程序是否已连接,但仍然无法弄清楚我遇到的问题。
$server = "IDEA-PC'SQLEXPRESS";
$dbGet = array("Database"=>"LogboxDB");
$con = sqlsrv_connect($server, $dbGet) or die (sqlsrv_error());
if(!$con)
{
die(print_r(sqlsrv_errors(), true));
}
else
{
echo 'Connected';
}
这是我的错误。
致命错误:调用未定义的函数 sqlsrv_connect();
我怎样才能摆脱这个问题?
您需要启用扩展支持才能在 PHP 中使用 MSSQL 服务器。它可以通过编辑 php 来启用.ini如下所示。
扩展名=php_sqlsrv.dll
您可以从 http://docs.gurock.com/testrail-admin/howto-installing-sqlsrv 中卸载包
试试这个
$serverName = "192.168.1.223, 1433"; //serverName'instanceName - change it as yours
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"LogboxDB", "UID"=>"username", "PWD"=>"password");
$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));
}