无法通过PHP连接到msSQL数据库 [英] Unable to connect to msSQL database via PHP

查看:364
本文介绍了无法通过PHP连接到msSQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用当前代码尝试访问一个msSQL 2005 db:

I am using the current code in attempt to access a msSQL 2005 db:

<?php
$myServer = "[server]";
$myUser = "[username]";
$myPass = "[password]";
$myDB = "[db]";

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer");

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB");

//declare the SQL statement that will query the database
$query = "SELECT id, name, year ";
$query .= "FROM cars ";
$query .= "WHERE name='BMW'";

//execute the SQL query and return records
$result = mssql_query($query);

$numRows = mssql_num_rows($result);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";

//display the results
while($row = mssql_fetch_array($result))
{
  echo "<li>" . $row["id"] . $row["name"] . $row["year"] . "</li>";
}
//close the connection
mssql_close($dbhandle);
?>

它返回以下内容:

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: XXXXXXX in D:\xxxxx.xxx\xxxx.php on line 16
Couldn't connect to SQL Server on XXXXXXX

您认为问题是什么?

推荐答案

听起来像我的一个DLL是错误的版本。有一个问题,从SQL2000到SQL2005,PHP的创造者没有解决自己。有这里的各种帖子:以下链接

It sounds to me like one of your DLLs is the wrong version. There was an issue of some sort with the move from SQL2000 to SQL2005 that the creators of PHP didn't resolve themselves. There are a variety of posts about it here: the following link

我相信DLL是ntwdblib.dll,版本至少需要是版本2000.80.194.0。如果您正在运行Apache或WampServer,则存在一个相同的dll,其中存储需要覆盖的Apache DLL。

I believe the DLL is ntwdblib.dll and the version needs to be version 2000.80.194.0 at the very least. If you're running Apache or WampServer, there is an identical dll where the Apache DLLs are stored that needs to be overwritten.

这里是一个下载链接到dll版本,将工作 http://www.mdome.org/2011/05/04/php-and-sql-server-2008-r2- ntwdblib-dll /

Here is a download link to a dll version which will work http://www.mdome.org/2011/05/04/php-and-sql-server-2008-r2-ntwdblib-dll/

注意:我几天前遇到了这个问题,发现正确的DLL和覆盖都允许它工作。

Note: I was having this issue a few days ago and finding the correct DLLs and overwriting both allowed it to work.

此外:您可能需要设置远程连接。默认情况下,Sql Server 2005已禁用远程连接。您可以通过运行SQL表面区域配置实用程序来允许远程连接。

Also: You may need to setup remote connections. Sql Server 2005 has remote connections disabled by default. You can allow remote connections by running the SQL Surface Area Configuration utility.

这篇关于无法通过PHP连接到msSQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆