Wordpress 致命错误:未捕获的错误:调用 /wp-includes/wp-db.php:1570 中未定义的函数 mysql_connect()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44841823/
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
Wordpress Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /wp-includes/wp-db.php:1570
提问by Thomas
I am in big trouble. I installed a nulled version of woocommerce cart based shipping plugin and i found it not relevant according to my requiremnet and deleted that plugin from plugins area. After deleting that plugin my site went down. Its continuously showing me Fatal error:
我遇到了大麻烦。我安装了一个基于 woocommerce 购物车的运输插件的空版本,我发现它与我的需求无关,并从插件区域中删除了该插件。删除该插件后,我的网站宕机了。它不断向我显示致命错误:
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /home/dev/public_html/new/wp-includes/wp-db.php:1570
Stack trace:
#0 /home/dev/public_html/new/wp-includes/wp-db.php(658): wpdb->db_connect()
#1 /home/dev/public_html/new/wp-includes/load.php(404): wpdb->__construct('dev_test', 'password', 'dev_test_ne...', 'localhost')
#2 /home/dev/public_html/new/wp-settings.php(107): require_wp_db()
#3 /home/dev/public_html/new/wp-config.php(82): require_once('/home/dev/p...')
#4 /home/dev/public_html/new/wp-load.php(37): require_once('/home/dev/p...')
#5 /home/dev/public_html/new/wp-blog-header.php(13): require_once('/home/dev/p...')
#6 /home/dev/public_html/new/index.php(17): require('/home/dev/p...')
#7 {main} thrown in /home/dev/public_html/new/wp-includes/wp-db.php on line 1570
I tried replacing all core files excluding wp-config.php and wp-content folder. Still I am getting the same error.
我尝试替换除 wp-config.php 和 wp-content 文件夹之外的所有核心文件。我仍然遇到同样的错误。
Also, i tried renameing plugins folder but the error is there.
另外,我尝试重命名插件文件夹,但错误在那里。
Can you guys suggest me how i can get my site back.
你们能建议我如何让我的网站回来。
回答by Schakko
Possible error sources:
可能的错误来源:
- Since PHP 7,
mysql_*
functions have been removed, see PHP's official overview of the MySQL drivers. - You use PHP 5.x and have not enabled the
mysql
extension, butmysqli
and/orpdo_mysql
instead.
- 自 PHP 7 起,
mysql_*
函数已被删除,请参阅PHP 对 MySQL 驱动程序的官方概述。 - 您使用 PHP 5.x 并且没有启用
mysql
扩展,而是mysqli
和/或pdo_mysql
代替。
You can set
你可以设置
define('WP_USE_EXT_MYSQL', true);
in your wp-config.php
file to make WordPress use the mysqli extension.
在您的wp-config.php
文件中让 WordPress 使用 mysqli 扩展。
回答by Rob Hoff
I encountered this problem upgrading from PHP 5 to PHP 7 (on Windows). The problem was mysqli
PHP extension was not enabled. If mysqli is not available Wordpress 5+ detects this and will instead attempt to connect to the database with deprecated mysql_connect()
calls. This leads to a very misleading error message about mysql_connect() function not being available (since we don't want this function).
我遇到了从 PHP 5 升级到 PHP 7(在 Windows 上)的问题。问题是mysqli
未启用 PHP 扩展。如果 mysqli 不可用,Wordpress 5+ 会检测到这一点,并将尝试使用不推荐使用的mysql_connect()
调用连接到数据库。这会导致关于 mysql_connect() 函数不可用的非常具有误导性的错误消息(因为我们不想要这个函数)。
In php.inimake sure extension_dir
is set (use full directory name) and mysqli extension is enabled
在php.ini 中确保extension_dir
已设置(使用完整目录名)并启用 mysqli 扩展
extension_dir = "C:\php-7.3.10\ext"
...
extension=mysqli
To double check what extensions are active you can run the following code
要仔细检查哪些扩展程序处于活动状态,您可以运行以下代码
<pre>
<?php print_r(get_loaded_extensions()); ?>
</pre>
回答by Rinalds A?i??-Bikars
It happens for me when I switch from 5.6 php to 7.0.
当我从 5.6 php 切换到 7.0 时,它发生在我身上。
Just enable "mysqli" in your select php version if you use cPanel.
如果您使用 cPanel,只需在您选择的 php 版本中启用“mysqli”。
回答by Simon
Please check your wp-config.php file for the following line:
请检查您的 wp-config.php 文件中的以下行:
define('WP_USE_EXT_MYSQL', true);
If you find it, delete the line. Your problem should be fixed.
如果找到,请删除该行。你的问题应该得到解决。
If not, you can tick nd_mysqli
extension in the PHP 7 configuration, and disable the mysqli
extension on Cpanel -> Select PHP version.
如果没有,您可以nd_mysqli
在 PHP 7 配置中勾选扩展,并mysqli
在 Cpanel 上禁用扩展 -> 选择 PHP 版本。
Source:
来源:
https://wordpress.org/support/topic/database-cache-causing-503-errors-when-upgrading-to-php-7/
https://wordpress.org/support/topic/database-cache-causing-503-errors-when-upgrading-to-php-7/
Hope this helps. :)
希望这可以帮助。:)
回答by Ryosaku
The error seems be simple, mysql_*
functions are not enabled.
Check with phpinfo()
if these functions are truly disabled, and if yes, enable it.
If no, there are some problems in the code that you are using, but if you have replaced all files as you write, is most probably the first option.
错误似乎很简单,mysql_*
功能未启用。检查phpinfo()
这些功能是否真的被禁用,如果是,启用它。如果不是,则您使用的代码存在一些问题,但如果您在编写时替换了所有文件,则很可能是第一个选项。
回答by Paul R
Just had a similar problem with a cpanel multiphp instance. Tried just about everything but while cpanel/whm was saying all was fine, the site would crash when 7.x was activated.
cpanel multiphp 实例刚刚遇到了类似的问题。尝试了几乎所有的东西,但是当 cpanel/whm 说一切都很好时,当 7.x 被激活时网站会崩溃。
In the end, it was the .htaccess file. We renamed and let Cpanel regenerate and all is good.
最后,它是 .htaccess 文件。我们重命名并让 Cpanel 重新生成,一切都很好。
Hope this helps someone out there as it took some time to resolve here.
希望这可以帮助那里的人,因为这里需要一些时间来解决。
回答by Misophoniq
Just registered to give a big thank you for the solution of enabling mysqli. I have been struggling to get WordPress running on a Synology for the past 3.5 hours and this finally fixed my dreaded "The site is experiencing technical difficulties."
刚刚注册,非常感谢您提供启用mysqli的解决方案。在过去的 3.5 小时里,我一直在努力让 WordPress 在 Synology 上运行,这终于解决了我可怕的“网站遇到技术问题”的问题。
For any other Synology users ending up in this topic after trying to find a solution, to fix this on Synology, you need to...
对于在尝试找到解决方案后最终遇到此主题的任何其他 Synology 用户,要在 Synology 上解决此问题,您需要...
- Go to Web Station
- Select PHP Settings
- Double-click the PHP profile you are using (or click once and choose [Edit])
- Select General Settings and scroll to the extensions list
- Find mysqli and enable by placing a checkmark
- Push the [OK] button (no restart required)
- 前往网络站
- 选择 PHP 设置
- 双击您正在使用的 PHP 配置文件(或单击一次并选择 [编辑])
- 选择常规设置并滚动到扩展列表
- 找到 mysqli 并通过勾选标记启用
- 按 [OK] 按钮(无需重新启动)