开发者社区> 科技小能手> 正文

php在iis上配置时报Fatal error: Call to undefined function mysql_connect() in 错误解决办法

简介:
+关注继续查看
php5与apache工作没有问题,但是和iis整合不到一起,访问数据库时会报错:Fatal error: Call to undefined function mysql_connect() in

看phpinfo页面发现,没有加载到php.ini文件,即在phpinfo中查看时发现应该去到c:\windows里面找php.ini文件,可是没有读取到,但是在c:\windows目录中确实有php.ini文件,情况如下:

Configuration File (php.ini) Path C:\WINDOWS 
Loaded Configuration File (none) 

解决办法,说实话也不知道是哪一步是彻底解决问题的,反正一个是在系统的环境变量中加了一个PHPRC,让这个PHPRC去指向我的php安装目录,另外一个是执行了一下iisreset,之后就可以了,不过那也不是读取的c:\windows\php.ini,是读取的php安装目录中的ini文件,反正操作数据库是没错误了。

参考文章:

It seems every time I try to install PHP and MySQL something doesn't work - usually there's either a file missing from the PHP distro or something in the install notes is missing or incorrect.  This time it was both.

I first tried the PHP msi install - first mistake.  As it does not include the MySQL extensions - neither does the 5.2.6 PECL zip file (I mistakenly thought this would include all the extensions).  So if you've installed PHP using the MSI installer - uninstall it (via Control Panel - Add/Remove Programs).  Also - you may need to manually remove any remants of this PHP installation manually - I had to manually delete the php directory.

Now with a clean slate do the following:

   1. Download the PHP zip package from here.
   2. Extract the zip - in my case into C:\PHP5
   3. Copy php.ini-recommended and rename it to php.ini (within this same dir).
   4. Edit php.ini and make the following changes:
         1. Set the extension dir eg:
            extension_dir = "C:\PHP5\ext"
         2. Uncomment the extension setting for mysql eg remove the ';' from the beginning of the line:
            extension=php_mysql.dll
   5. Within IIS admin tool:
         1. Within Application Configuration (within 'Home Directory' of a site) add the php extension - mapping 'php' to php5isapi.dll (eg D:\php-5.2.6-Win32\php5isapi.dll).
         2. Within Web Service Extensions add one for php5isapi.dll (eg D:\php-5.2.6-Win32\php5isapi.dll) setting it to 'Allowed'.
   6. Update the PATH environment variable to include the php dir eg D:\php-5.2.6-Win32.
   7. Add a new environment variable called PHPRC and set to the php dir eg D:\php-5.2.6-Win32  (this part was missing from the install docs for IIS).
   8. Restart iis (eg run iisreset from the command prompt).

Bingo - that's it. To test create a file called phpinfo.php (and place in the web root) with the following:
<?php
phpinfo();
?>

The critical part to check here is that the output of this phpinfo shows the 'Loaded Configuration File' is set to the php.ini file you created above.  If PHP is configured correctly to use mysql it this (phpinfo output) will have a MySQL section - if this is missing - then something is wrong.


本文转自holy2009 51CTO博客,原文链接:http://blog.51cto.com/holy2010/387037


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
PHP5.5 + IIS + Win7的配置
PHP5.5 + IIS + Win7的配置
50 0
Window2003 iis+mysql+php环境配置:
1.下载php mysql zend phpmyadmin 建议到这里下载:链接:http://pan.baidu.com/s/1i3xN5Yl 密码:onmn 这个软件包已经包含 php 5.2.17 mysql 5.1.63 zend phpwind 8.7 phpmyadmin 3.5.2 省去大家到各个网站找包的时间。
85 0
文章
问答
文章排行榜
最热
最新
相关电子书
更多
PHP安全开发_从白帽角度做安全
立即下载
PHP在机器学习上的应用及云深度学习平台的架构设计与实现
立即下载
PHP与APM_技术内幕和最佳实践
立即下载