喜欢本站并加入收藏
首 页 电脑学园 技术文档 图形图像 办公应用 网页设计 管理资料 PPT模板 方案合同
 位置: 北方教程网 >> 网页设计 >> PHP专题 >> 正文
   PHP无法连接MSSQL数据库问题的解决
PHP无法连接MSSQL数据库问题的解决
[ 作者:佚名   来源:网络整理   点击数:   更新时间:2007-4-2 ]

配置了新服务器,配置是IIS+php,结果运行时发现php连接远程mssql数据库出错,出错代码如下:
Warning: mssql_connect(): Unable to connect to server:

想想以前都是没问题的,怎么回事呢?后来去网上搜索,发现一篇文章,才发现原来服务器是需要安装mssql才能用php连接mssql的,本来新服务器上我是不需要用到mssql的,但是现在没办法了,只能把它装上了,安装了mssql之后就没问题了。

我在想,如果是在linux上面的apache+php会怎样呢,不可能需要安装mssql吧,呵呵,晕了。

下面是找到的一篇文章。

php配置:
在php.ini文件里设置如下,找到 
;extension=php_mssql.dll  把前面的分号去掉 
找到extension_dir  =  d:\extension\ 
你的php.ini里面可能不是d:\extension\ 
改成在php安装目录下面的extensions目录下面的php_mssql.dll,所在的路径,如果你没有把它移动到其他地方(假设你的php安装路径是d:\php) 
就改成extension_dir=d:\php\extensions\ 
然后重新启动web服务器


这一点很容易做到,但是做完这样的设置后还是连不上,错误的信息如下:

MS SQL Server 数据库连接错误!请检查数据库主机变量设置是否正确!!!

而主机的变量设置我是一遍一遍的检查,那些设置是一点问题都没有的,翻遍网页,找到了下面的这点蛛丝马迹:


php.com资料:

I am trying to connect to SQL Server 2000 from PHP
I bumped to following warning:
Warning: mssql_connect(): Unable to connect to server: SERVER\Portal
....... on line 5

on line 5 there is:
$db_connect = mssql_connect('SERVER\Portal', 'sa', 'my_passwd');

I did the following
1.enabled php_mssql.dll extension in PHP.ini
2.every dll is in proper place(System32 or PHP folder),including ntwdblib.dll

I search lots of profile throught web ,but no one give me proper answer to resolve it.

after a few hour ,I found the problem was caused by
ntwdblib.dll ,which version is 7.00.839 ,when I replaced old ntwdblib.dll with the new

ntwdblib.dll ,which version is 8.00.194 ,all problem are solved.

We had some, read A LOT, of problems with MSSQL under Windows 2003.
We had 2 the same windows, php, php-ini, everything machines but only one could connect.

Unable to connect was the error message.

Finnaly we checked the version of ntwdblib.dll and the one distributed with PHP was 7.00....

and the version of the one on the SQL Server install was 8.00.... so we copied this one in

the php and apache dir and it worked.

问题就这样被找到了,惹祸的是它 ntwdblib.dll

ntwdblib.dll的主要作用是提供sql server连接服务。

我用的php版本是4.3.9,在安装它的服器的 windows/system32/ 下我查到ntwdblib.dll文件的版本是2000.2.8.0 ,这个版本支持的是sql server 7.0, 因为安装PHP时会把dlls下面的所有文件覆盖到系统

目录下,所以当我用它去连接 sql server 2000 的时候当然会是无法连接了。

后来我在一台正常安装sql server 2000 的服务器上查到 ntwdblib.dll的版本是 2000.80.2039.0,我把这个文件拷过去,覆盖掉以前的版本,重启服务器后,一切正常。
 
补充:如果数据库名的开头是数字时也会提示无法打开,这时要做的很简单,把数据库的名字用中括号 [ ]
括起来就搞定了,如 123bbs 改写成 [123bbs]就没有问题了,另外如果你的数据库名字与sql server中的保留字冲突的话也会出现这种情况,用中括号的方法一样可以解决。

最终,PHP无法正确连接sql server 2000的问题终于解决了,虽然耗费大半天的时间,但收获还是很大的,现在把它贴出来,也让遇到同样问题的兄弟们少走一些弯路。

上一篇文章: php实现文本数据翻页(留言本翻页) 下一篇文章: PHP自动把纯文本转换成Web页面
打印此文  收藏此页  关闭窗口  返回顶部
 相关文章  热点文章
 · 利用CSS改进网站设计的小技巧
 · Dreamweaver快捷操作技巧集锦
 · 使用Dreamweaver架设网站简明教程
 · 网页设计制作过程中常用的几个代码技巧
 · 高效使用CSS编码的方法
 
热点图文
教你节省Vist...
使用Windows ...
 · 远程管理Web服务器的方法技巧
 · Win Vista系统自带IIS7.0设置详解...
 · 详解Windows系统IIS6.0功能及应用...
 · 服务器集群系统实现方法及案例分...
 · IIS服务器实现asp,cgi和php+mysq...
 · IIS下SQL Server数据库安全设置技...
推 荐 阅 读
巧用Photosho...
Photoshop鼠绘...
 · Fireworks制作旋转的漂亮gif动画...
 · Photoshop制作都市满天繁星
 · Fireworks制作Menu按钮
 · 巧用Photoshop制作喜迎奥运壁纸
 · 巧用Photoshop钢笔工具绘制彩色美...
 · Photoshop制作浪漫动感花朵
 设为首页 - 加入收藏 - 关于本站 - 联系我们 - 广告合作 - 友情链接 - 在线交流 - 
CopyRight© 2006-2009 Eduai.Com All Rights Reserved
在线交流 QQ:524152258 辽ICP备07001851号
免责声明:本站部分资源来自网络,如有侵犯您的版权请通知,我们立即删除。