使用 PHP 连接到 MSSQL Server 2008
我们在 Win server 2008 R2 上使用 MSSQL server 2008,并分别安装了 Apache (2.2.19)
和 PHP (5.2.17)
。我们已经安装了 PHP 的 MSSQL 模块并使用以下连接字符串:
$myc = mssql_connect(Server, SiteDatabaseUsername, SiteDatabasePassword) or die('Can\'t connect to mssql Database Server: '.mssql_get_last_message($myc));
$db = mssql_select_db(SiteDatabaseName, $myc) or die('Can\'t find database: '.mssql_get_last_message($myc));
但它给了我们这个错误:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost\MSSQLSERVER in D:\Apache2.2\htdocs\adminarea\_core.php on line 89
Can't connect to mssql Database Server:
我们使用了 IP:PORT
、localhost\MSSQLSERVER
和 COMPUTERNAME\MSSQLSERVER
但似乎没有任何进展,有人可以帮忙吗?
We are using MSSQL server 2008 on Win server 2008 R2 and have installed Apache (2.2.19)
and PHP (5.2.17)
separately. We have installd the MSSQL module for PHP and usingthe following connection string:
$myc = mssql_connect(Server, SiteDatabaseUsername, SiteDatabasePassword) or die('Can\'t connect to mssql Database Server: '.mssql_get_last_message($myc));
$db = mssql_select_db(SiteDatabaseName, $myc) or die('Can\'t find database: '.mssql_get_last_message($myc));
But it gives us this error:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost\MSSQLSERVER in D:\Apache2.2\htdocs\adminarea\_core.php on line 89
Can't connect to mssql Database Server:
We have used the IP:PORT
, localhost\MSSQLSERVER
and COMPUTERNAME\MSSQLSERVER
but don't seem to be getting anywhere, can anyone help please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意以下几点:
1) 确保您拥有来自 MS 的 sqlsrv 驱动程序包,并确保您在 php.ini 中正确加载它(使用 phpinfo() 进行验证)。
2) 如果这是 SQL Server 的普通安装,则可能只打开了 Windows 身份验证。打开 SQL 企业管理器并确保在数据库上启用了 SQL Server 身份验证。
3) 确保您已启用对 SQL Server 的网络访问。我不能立即确定新的 MS 驱动程序是否使用命名管道与服务器通信,或者他们是否期望通过网络访问服务器。
这些是我在让 PHP 与新的 MSSQL 服务器对话时经常遇到的问题。
A few things come to mind:
1) Make sure you have the sqlsrv driver package from MS, and make sure you're loading it properly in php.ini (use phpinfo() to verify).
2) If this was a vanilla installation of SQL Server, its likely that only windows authentication is turned on. Open the SQL Enterprise Manager and make sure you have SQL Server Authentication enabled on your database.
3) Make sure that you have enabled network access to SQL Server. I'm not immediately certain whether the new MS drivers use named pipes to communicate with the server, or if they expect that the server will be accessed via the network.
These are the issues I routinely encounter when getting PHP speaking to a new MSSQL server.