php 调用未定义的函数 mysql_connect
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8551398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call to undefined function mysql_connect
提问by Nikolas Jí?a
I just installed PHP and Apache on my home PC. When I try to call function mysql_connect
I get:
我刚刚在我的家用 PC 上安装了 PHP 和 Apache。当我尝试调用函数时,mysql_connect
我得到:
fatal error: call to undefined function mysql_connect.
I have loaded php.ini where I have uncommented lines extension=php_mysql.dll
and
extension=php_mysqli.dll
and changed extension directory to extension_dir = "C:\php\ext"
- which is the directory where files php_mysql.dll and php_mysqli.dll are. How can I fix this problem?
我已经加载了 php.ini,其中我有未注释的行extension=php_mysql.dll
,
extension=php_mysqli.dll
并将扩展目录更改为extension_dir = "C:\php\ext"
- 这是文件 php_mysql.dll 和 php_mysqli.dll 所在的目录。我该如何解决这个问题?
Output of phpinfo():http://jsfiddle.net/MMTwA/
phpinfo() 的输出:http : //jsfiddle.net/MMTwA/
采纳答案by Bryan
After looking at your phpinfo()
output, it appears the mysql extensions are not being loaded. I suspect you might be editing the wrong php.ini file (there might be multiple copies). Make sure you are editing the php file at C:\php\php.ini(also check to make sure there is no second copy in C:\Windows).
查看您的phpinfo()
输出后,似乎没有加载 mysql 扩展。我怀疑您可能正在编辑错误的 php.ini 文件(可能有多个副本)。确保您正在编辑C:\php\php.ini 中的 php 文件(还要检查以确保 C:\Windows 中没有第二个副本)。
Also, you should check your Apache logs for errors (should be in the \logs\ directory in your Apache install.
此外,您应该检查 Apache 日志是否有错误(应该在 Apache 安装的 \logs\ 目录中。
If you haven't read the below, I would take a look at the comments section, because it seems like a lot of people experience quirks with setting this up. A few commenters offer solutions they used to get it working.
如果你还没有阅读下面的内容,我会看看评论部分,因为似乎很多人在设置它时都遇到了怪癖。一些评论者提供了他们用来使其工作的解决方案。
http://php.net/manual/en/install.windows.extensions.php
http://php.net/manual/en/install.windows.extensions.php
Another common solution seems to be to copy libmysql.dll and php_mysql.dll from c:\PHP to C:\Windows\System32.
另一个常见的解决方案似乎是将 libmysql.dll 和 php_mysql.dll 从 c:\PHP 复制到 C:\Windows\System32。
回答by Drigs
Background about my (similar) problem:
关于我的(类似)问题的背景:
I was asked to fix a PHP project, which made use of short tags. My WAMP server's PHP.ini had short_open_tag = off
.
In order to run the project for the first time, I modified this setting to short_open_tag = off
.
我被要求修复一个使用短标签的 PHP 项目。我的 WAMP 服务器的 PHP.ini 有short_open_tag = off
. 为了第一次运行项目,我把这个设置修改为short_open_tag = off
.
PROBLEM Surfaced: Immediately after this change, all my mysql_connect() calls failed. It threw an error
问题浮出水面:此更改后,我的所有 mysql_connect() 调用立即失败。它抛出了一个错误
fatal error: call to undefined function mysql_connect.
致命错误:调用未定义的函数 mysql_connect。
Solution:
Simply set short_open_tag = off
.
解决方案:只需设置short_open_tag = off
.
回答by Darius Miliauskas
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. You can check if "php.ini" is read from the right directory. Just type in your browser "localhost/index.php". The code of index.php is the following:
我的电脑运行的是 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) 对斜杠很敏感。您可以检查是否从正确的目录中读取了“php.ini”。只需在浏览器中输入“localhost/index.php”。index.php 的代码如下:
<?php
echo phpinfo();
?>
<?php
echo phpinfo();
?>
There is the row (not far from the top) called "Loaded Configuration File". 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). So, in order to make it work I did the following step. I needed to change from
有一行(离顶部不远)称为“加载的配置文件”。因此,如果没有添加任何内容,那么问题可能是您的“php.ini”未被读取,即使您取消注释(extension=php_mysql.dll 和 extension=php_mysqli.dll)。所以,为了使它工作,我做了以下步骤。我需要改变
PHPIniDir 'c:\PHP\'
PHPIniDir 'c:\PHP\'
to
到
PHPIniDir 'c:\PHP'
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. MySQL and PHP are working together!
现在,在刷新“localhost/index.php”(在我重新启动 Apache2.2 之前)以及 mysql 块之后,“加载的配置文件”行获得了“C:\PHP\php.ini”。MySQL 和 PHP 正在协同工作!
回答by jagumon
Check your php.ini, I'm using Apache2.2 + php 5.3. and I had the same problem and after modify the php.ini in order to set the libraries directory of PHP, it worked correctly. The problem is the default extension_dir
configuration value.
检查您的 php.ini,我使用的是 Apache2.2 + php 5.3。我遇到了同样的问题,在修改 php.ini 以设置 PHP 的库目录后,它工作正常。问题是默认extension_dir
配置值。
The default (and WRONG) value for my work enviroment is
我的工作环境的默认(和错误)值是
; extension_dir="ext"
without any full path and commented with a semicolon.
没有任何完整路径并用分号注释。
There are two solution that worked fine for me.
有两种解决方案对我来说效果很好。
1.- Including this line at php.ini file
1.- 在 php.ini 文件中包含这一行
extension_dir="X:/[PathToYourPHPDirectory]/ext
Where X: is your drive letter instalation (normally C: or D: )
其中 X: 是您的驱动器号安装(通常是 C: 或 D: )
2.- You can try to simply uncomment, deleting semicolon. Include the next line at php.ini file
2.- 您可以尝试简单地取消注释,删除分号。在 php.ini 文件中包含下一行
extension_dir="ext"
Both ways worked fine for me but choose yours. Don't forget restart Apache before try again.
两种方式对我来说都很好,但选择你的。在重试之前不要忘记重新启动Apache。
I hope this help you.
我希望这对你有帮助。
回答by Martin.
You have probably forgotten to restart apache/wamp/xamp/whatever webserver you use, you need to do that in order to make it work
您可能忘记重新启动 apache/wamp/xamp/无论您使用什么网络服务器,您都需要这样做才能使其正常工作
回答by nobjta_9x_tq
Be sure you edited php.ini in /php folder, I lost all day to detect error and finally I found I edited php.ini in wrong location.
确保你在 /php 文件夹中编辑了 php.ini,我花了一整天的时间来检测错误,最后我发现我在错误的位置编辑了 php.ini。
回答by zzapper
Hi I got this error because I left out the ampersand (&) in
嗨,我收到此错误是因为我遗漏了与号 (&)
; php.ini
error_reporting = E_ALL & ~E_DEPRECATED
回答by mark
This same problem drove me nuts (Windows 10, Apache 2.4, MySql 5.7). For some reason (likely PATH related), the .dlls would not load after uncommenting the correct exension dlls and extension_dir = "ext" in php.ini. After trying numerous things, I simply changed "ext" to use the full directory path. For example. extension_dir = "c:/phpinstall/ext" and it worked.
同样的问题让我抓狂(Windows 10、Apache 2.4、MySql 5.7)。由于某种原因(可能与 PATH 相关),在 php.ini 中取消注释正确的扩展 dll 和 extension_dir = "ext" 后,.dll 不会加载。在尝试了很多事情之后,我只是将“ext”更改为使用完整目录路径。例如。extension_dir = "c:/phpinstall/ext" 并且它起作用了。
回答by Pascal
Since mysql_connect This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. by default xampp does not load it automatically
由于 mysql_connect 这个扩展在 PHP 5.5.0 中被弃用,在 PHP 7.0.0 中被移除。相反,应使用 MySQLi 或 PDO_MySQL 扩展。默认情况下,xampp 不会自动加载它
in your php.ini file you should uncomment
在你的 php.ini 文件中,你应该取消注释
;; extension=php_mysql.dll
to
到
extension=php_mysql.dll
Then restart your apache you should be fine
然后重启你的apache你应该没问题
回答by Pepe Yá?ez
One time I had a problem while using Off
instead of off
. And also check the pads one more time... The path has to be exact. Also add the following line to your environmental variable.
有一次我在使用Off
而不是off
. 还要再检查一次垫子……路径必须准确。还将以下行添加到您的环境变量中。
C:\your-apache-path\bin; C:\your-php-path\bin;C:\your-mysql-path\bin
If you are in Windows, right click My Computer, select properties, and navigate to the Advancedtab... (is Windows 7). Click on Advanced system settings first then select the Advancedtab and then Environmental variables. Select PATH and click on Edit. Make a copy of the string in a .txt file for back up (it might be empty)--- set your environmental variables... Log out and log back in.
如果您使用的是 Windows,请右键单击我的电脑,选择属性,然后导航到高级选项卡...(是 Windows 7)。首先单击高级系统设置,然后选择高级选项卡,然后选择环境变量。选择 PATH 并单击编辑。在 .txt 文件中复制该字符串以进行备份(它可能为空)--- 设置您的环境变量...注销并重新登录。