简体   繁体   English

致命错误:调用未定义函数mysql_connect()无法解决

[英]Fatal error: Call to undefined function mysql_connect() cannot solve

I have searched this error in Google and tried everything I found, but it still does not work. 我已经在Google中搜索了此错误,并尝试了所有发现的错误,但仍然无法正常运行。 I have set in my php.ini 我已经在我的php.ini中设置了

extension_dir ="C:\php\ext\"

uncommented 没有评论

extension=php_mysql.dll
extension=php_mysqli.dll

these files are present in the extension path, and I restarted Apache. 这些文件位于扩展路径中,我重新启动了Apache。 But phpinfo(); 但是phpinfo(); still does not show anything about MySQL. 仍然没有显示有关MySQL的任何信息。 So do you have any suggestions to load these modules? 那么您对加载这些模块有什么建议吗?

note: I am using Windows 7 (64 bit), MySQL 5.5, Apache 2.0.49 and PHP 5.3.16 注意:我正在使用Windows 7(64位),MySQL 5.5,Apache 2.0.49和PHP 5.3.16

Finally, I solved the same problem, so, here is my solution. 最后,我解决了相同的问题,因此,这是我的解决方案。 I guess the last slash in the line 我猜该行的最后一个斜杠

extension_dir ="C:\\php\\ext\\

could make troubles. 可能会造成麻烦。 Just let it as 就这样吧

extension_dir ="C:\\php\\ext

Moreover, try to approach the problem the following way: 此外,请尝试通过以下方式解决该问题:

*My PC is running Windows 7 (Apache 2.2 & PHP 5.2.17 & MySQL 5.0.51a), the syntax in the file "httpd.conf" (C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\conf\\httpd.conf) was sensitive to slashes. *我的电脑正在运行Windows 7(Apache 2.2和PHP 5.2.17和MySQL 5.0.51a),文件“ httpd.conf”中的语法(C:\\ Program Files(x86)\\ Apache Software Foundation \\ Apache2.2 \\ conf \\ httpd.conf)对斜杠敏感。 You can check if "php.ini" is read from the right directory. 您可以检查是否从正确的目录中读取了“ php.ini”。 Just type in your browser "localhost/index.php". 只需在浏览器中输入“ localhost / index.php”即可。 The code of index.php is the following: <?php echo phpinfo(); ?> index.php的代码如下: <?php echo phpinfo(); ?> <?php echo phpinfo(); ?> There is the row (not far from the top) called "Loaded Configuration File". <?php echo phpinfo(); ?>有一行(距离顶部不远)称为“已加载的配置文件”。 So, if there is nothing added, then the problem could be that your "php.ini" is not read, even you uncommented (extension=php_mysql.dll and extension=php_mysqli.dll). 因此,如果未添加任何内容,则问题可能是您的“ php.ini”未被阅读,即使您未注释(扩展名= php_mysql.dll和扩展名= php_mysqli.dll)。 So, in order to make it work I did the following step. 因此,为了使其正常工作,我做了以下步骤。 I needed to change from 我需要从

PHPIniDir 'c:\\PHP\\'

to

PHPIniDir 'c:\\PHP'

Pay the attention that the last slash disturbed everything! 请注意最后一个斜杠会干扰所有内容!

Now the row "Loaded Configuration File" gets "C:\\PHP\\php.ini" after refreshing "localhost/index.php" (before I restarted Apache2.2) as well as mysql block is there. 现在,在刷新“ localhost / index.php”(在我重新启动Apache2.2之前)之后,“已加载的配置文件”行将获得“ C:\\ PHP \\ php.ini”以及mysql块。 MySQL and PHP are working together!* MySQL和PHP一起工作!*

I have been having the exact same problem as you. 我一直和你有同样的问题。 And I (literally) solved it 2 minutes ago. 我(字面上)在2分钟前解决了问题。

I am running Apache 2.4 64 bit on Win 7. 我在Win 7上运行Apache 2.4 64位。

The version of php I downloaded gave me two php.ini files: 我下载的php版本给了我两个php.ini文件:

1)php.ini-production and 2)php.ini-development 1)php.ini-production和2)php.ini-development

I thought that was all gravy and every time I made a change to one, I did the exact same thing to the other. 我以为这是所有的肉汁,每当我更改一个时,我对另一个完全相同。

When I first encountered the problem I loaded index.php (on my local server) and looked at the sixth box from the top called "Loaded configuration file". 第一次遇到问题时,我在本地服务器上加载了index.php,并从顶部看了第六个框,即“已加载的配置文件”。 It simple said "nothing." 简单地说“没事”。

I then referenced this page and found how PHP (once started) goes about looking for the php.ini file. 然后,我参考了页面,发现PHP(一旦启动)如何查找php.ini文件。 I tried putting both the development and production (referenced above) files in all the directories that the above link specified. 我尝试将开发和生产(上面引用)文件都放在上述链接指定的所有目录中。 Nothing. 没有。

Then I thought, what the hell it's worth a shot, and changed the php.ini-production to just "php.ini". 然后我想,这到底是值得一试的,然后将php.ini-production更改为“ php.ini”。

Bam. am It started working. 它开始工作了。 Such a simplistic fix but I suppose it makes sense as to why Apache wasn't able to find "php.ini." 这样简单的修复,但是我认为对于Apache为什么找不到“ php.ini”是有道理的。 The file didn't exist verbatim. 该文件不完全存在。

I really hope this helps, running into this problem sure sucked. 我真的希望这会有所帮助,一定会遇到这个问题。

And I'm sorry if any of this seems patronizing because it is so simple. 非常抱歉,因为它是如此简单,所以其中的任何一项似乎都不受欢迎。 I always troubleshoot from this site and so many of the answers require more than a fundamental understanding of a subject, and since this seems like a problem(and a solution) that beginners will struggle with, I thought I would spell it out in a way that I would have appreciated 6 months ago. 我总是从该站点进行故障排除,因此许多答案不仅仅需要对某个主题有基本的了解,而且由于这似乎是初学者会遇到的问题(和解决方案),所以我想我会用一种方式来阐明我会在6个月前感谢您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM