Compiled PHP 7 missing mysql extension in WordPress

后端 未结 6 842
慢半拍i
慢半拍i 2020-12-15 05:51

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

Your PHP installation a

相关标签:
6条回答
  • 2020-12-15 06:09

    PHP 7 has removed mysql_* completely.

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

    0 讨论(0)
  • 2020-12-15 06:09

    This issue is caused by php 7.1.0-dev.

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

    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.

    0 讨论(0)
  • 2020-12-15 06:12

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

    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.

    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

    It's important to note that Wordpress 3.9 or later supports 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.

    0 讨论(0)
  • 2020-12-15 06:17

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

    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.

    0 讨论(0)
  • 2020-12-15 06:18

    On Ubuntu, I fixed this error by running

    sudo apt-get install php-mysql
    

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

    source

    0 讨论(0)
  • 2020-12-15 06:23

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

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

    An example of mysqli connection string:

    <?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:

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

    Note:

    That mysqli example handles a connection error

    0 讨论(0)
提交回复
热议问题