Filed under: 开发编程 | No Comments »
Posted on October 21st, 2011 by 李 方进
windows下PHP自带的php_mssql.dll在配置的时候容易出现各种各样的错误。这里我要推荐另外一个扩展——php_dblib.dll
1.首先下载
http://docs.moodle.org/20/en/Installing_MSSQL_for_PHP#Using_FreeTDS_on_Windows
网站提供四个下载,分别是PHP 5.2.x (vc6) Thread Safe、 PHP 5.2.x (vc6) Non Thread Safe、PHP 5.3.x (vc9) Thread Safe、PHP 5.3.x (vc9) Non Thread Safe,找到符合自己要求的(phpinfo就能查到)下载
2.下载后解压缩,将php_dblib.dll复制到php环境的ext目录下
3.php.ini中增加一句extension=php_dblib.dll
4.重启web服务器(apache、iis、nginx等等)
- <?php
- $link = mssql_connect('localhost', 'db_user', 'db_password');
- if(!$link) {
- echo'Could not connect';
- die('Could not connect: ' . mssql_error());
- }
- echo'Successful connection';
- mssql_close($link);
- ?>
执行一下以上PHP代码——Successful connection,大功告成。
经测试,在windows2003和windows2008下,能很好的操作ms sql server 2005数据库。
补充:悲剧的是,在实际运行过程中,发现对存储过程支持的并不好。于是,又折腾了半天,找到了另外一个替代方案,下一篇文章再来讲这个替代方案。
Filed under: 互联网络 | 2 Comments »
Posted on November 30th, 2009 by 李 方进