在 WordPress 中编译 PHP 7 缺少 mysql 扩展

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34289954/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:53:18  来源:igfitidea点击:

Compiled PHP 7 missing mysql extension in WordPress

phpmysqlwordpress

提问by

I have built PHP 7 with a configuration that worked for a previous version of PHP. Now my WordPress websites get the message:

我已经使用适用于以前版本的 PHP 的配置构建了 PHP 7。现在我的 WordPress 网站收到消息:

Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

您的 PHP 安装似乎缺少 WordPress 所需的 MySQL 扩展。

Other websites using mysqli do work. What am I missing?

其他使用 mysqli 的网站也能工作。我错过了什么?

I've also included all .so files with mysql in the name:

我还在名称中包含了所有带有 mysql 的 .so 文件:

extension=dba.so
extension=mysql.so
extension=mysqli.so
extension=mysqlnd_mysql.so
extension=mysqlnd_mysqli.so
extension=mysqlnd.so
extension=pdo.so
extension=pdo_mysql.so
extension=pdo_odbc.so
extension=odbc.so

采纳答案by Machavity

As has been mentioned elsewhere, the ext/mysqlfunctions have been removed. We've been talking about this for some time.

正如其他地方所提到的,这些ext/mysql功能已被删除。我们已经讨论了一段时间了

ext/mysql was built for MySQL 3.23 and only got very few additions since then while mostly keeping compatibility with this old version which makes the code a bit harder to maintain.

ext/mysql 是为 MySQL 3.23 构建的,从那时起只增加了很少的内容,同时主要保持与这个旧版本的兼容性,这使得代码更难维护。

If you're hell-bent on putting them back in, you can add them back to PHP 7 by using the ext/mysql PECL Library

如果你一心想把它们放回去,你可以使用ext/mysql PECL 库将它们添加回 PHP 7

It's important to note that Wordpress 3.9 or later supports mysqli

需要注意的是,Wordpress 3.9 或更高版本支持 mysqli

In WordPress 3.9, we added an extra layer to WPDB, causing it to switch to using the mysqli PHP library, when using PHP 5.5 or higher.

在 WordPress 3.9 中,我们向 WPDB 添加了一个额外的层,使其在使用 PHP 5.5 或更高版本时切换到使用 mysqli PHP 库。

回答by KiwiJuicer

PHP 7 has removed mysql_* completely.

PHP 7 已经完全删除了 mysql_*。

You need to use PDO or mysqli. Wordpress seems not to support this.

您需要使用 PDO 或 mysqli。Wordpress 似乎不支持这一点。

回答by BRoebie

mysql_*functions got deleted in PHP 7.0 update your code to mysqlior PDO

mysql_*函数在 PHP 7.0 中被删除,将您的代码更新为mysqliPDO

Also take a look at prepared statements if you are handling user input. To reduce the chance of SQL injections

如果您正在处理用户输入,还可以查看准备好的语句。减少SQL 注入的机会

An example of mysqli connection string:

mysqli 连接字符串示例:

<?php
$mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
?>

An example of pdo connection string:

pdo 连接字符串示例:

<?php
    $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
?> 

Note:

笔记:

That mysqli example handles a connection error

该 mysqli 示例处理连接错误

回答by Machavity

This issue is caused by php 7.1.0-dev.

此问题是由 php 7.1.0-dev 引起的。

I built another one with the same configuration version 7.0.0 and the issue was resolved.

我用相同的配置版本 7.0.0 构建了另一个,问题解决了。

This has nothing to do with WordPress since it will automatically try to use MySQLi when MySQL is not found. At least in WP 4.4.

这与 WordPress 无关,因为当找不到 MySQL 时,它会自动尝试使用 MySQLi。至少在 WP 4.4 中。

回答by Bruno Leite

Check if the Wordpress still using the Mysql extension that was removed in PHP7.

检查 Wordpress 是否仍在使用 PHP7 中删除的 Mysql 扩展。

http://php.net/manual/en/migration70.removed-exts-sapis.php

http://php.net/manual/en/migration70.removed-exts-sapis.php

The Mysqli and PDO extensions were kept. This is the reason your other websites are working.

保留了 Mysqli 和 PDO 扩展。这就是您的其他网站正常工作的原因。

回答by Keith

On Ubuntu, I fixed this error by running

在 Ubuntu 上,我通过运行修复了这个错误

sudo apt-get install php-mysql

And then restarting my server (caddy, but you might be using apache or nginx).

然后重新启动我的服务器(球童,但您可能正在使用 apache 或 nginx)。

source

来源