PHP Startup: Unable to load dynamic library

昨天帮一朋友配置服务器结果发现apache日志中有PHP Warning: PHP Startup: Unable to load dynamic library 提示了,然后调试数据库连接发现提示Call to undefined function mysql_connect()错误,这样就想到了是mysql没有加载成功了,下面我们一起来看看问题解决办法.

连接代码:

  1. <?php
  2. echo 'a';
  3. $cn = mysql_connect("localhost",'你的mysql用户名','你的mysql用户密码') or die(mysql_error());//开源代码phpfensi.com
  4. if( $cn )
  5. {
  6. echo phpinfo();
  7. }
  8. else
  9. {
  10. echo 'mysql connect fail';
  11. }
  12. ?>

因为服务器使用的是安全php.ini所在没有错误显示,于时相看了apache安装目录的logs的errors.log日志文件发现如下错误:

  1. PHP Warning: PHP Startup: Unable to load dynamic library
  2. 'D:\myserver\php\ext\php_mysql.dll' - xd5xd2xb2xbbxb5xbdxd6xb8xb6xa8xb5xc4xc4
  3. xa3xbfxe9xa1xa3rn in Unknown on line 0
  4. PHP Warning: PHP Startup: Unable to load dynamic library
  5. 'D:\myserver\php\ext\php_mysqli.dll' - xd5xd2xb2xbbxb5xbdxd6xb8xb6xa8xb5xc4
  6. xc4xa3xbfxe9xa1xa3rn in Unknown on line 0
  7. [Tue Dec 31 09:05:15 2013] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined
  8. function mysql_connect() in E:\www\a.php on line 2, referer: http://localhost/
  9. [Tue Dec 31 09:05:16 2013] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined
  10. function mysql_connect() in E:\www\a.php on line 2, referer: http://localhost/
  11. [Tue Dec 31 09:05:17 2013] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined
  12. function mysql_connect() in E:\www\a.php on line 2, referer: http://localhost/
  13. [Tue Dec 31 09:06:04 2013] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined
  14. function mysql_connect() in E:\www\a.php on line 3, referer: http://localhost/
  15. [Tue Dec 31 09:06:05 2013] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined
  16. function mysql_connect() in E:\www\a.php on line 3, referer: http://localhost/
  17. [Tue Dec 31 09:06:05 2013] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined
  18. function mysql_connect() in E:\www\a.php on line 3, referer: http://localhost/
  19. [Tue Dec 31 09:06:05 2013] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined
  20. function mysql_connect() in E:\www\a.php on line 3, referer: http://localhost/
  21. [Tue Dec 31 09:06:06 2013] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined
  22. function mysql_connect() in E:\www\a.php on line 3, referer: http://localhost/
  23. [Tue Dec 31 09:06:06 2013] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined
  24. function mysql_connect() in E:\www\a.php on line 3, referer: http://localhost/

日志中有这么一句:PHP Startup: Unable to load dynamic library 'D:\myserver\php\ext\php_mysql.dll' 这个意思是没有加载成功php_mysql文件了,还有一点是提示 PHP Fatal error: Call to undefined function mysql_connect(),,这个是mysql没有连接成功也就是加载mysql库失败了,根据分析有两种可能一是文件不存在,这个问题不存因为我以前用的是这个php解压包,2是服务器环境变量问题,如果是环境变量有两种解决办法.

1,是直接在windows增加环境变量

2,直接把在d:PHP里找到php5ts.dll,libmysql.dll将其复制到c:/winnt/system32下(winNT/2000的机器),而winXP/2003是复制到c:/windows/system32下即可,记住复制到system目录之后必须重记apache环境,如我再测试http://localhost/a.php 就可以看到输出的phpinfo相关信息了.