0

After upgrading from ubuntu 14.03 to 16.04. I cannot connect to mysql from php DB. The following code returns

<?php
    include_once('DB.php');    
    $conninfo = "mysql://xxxx:ppppp@localhost/ddddd";
    $db = DB::connect($conninfo);        
    if (DB::isError($db)) {
        print $db->getMessage();
        exit;
    } else {
        $result = $db->query("SELECT distinct did from selections where cid=6 order by did DESC;");
        while ($result->fetchInto($row, DB_FETCHMODE_ASSOC)) {
            extract($row);
            print "$did\n";
        }
        $result->free();
    }
    $db->disconnect();
?>

DB Error: extension not found.

Note that from mysql, opened from the terminal, I see the contents of the table's column 'did'.

Following the advice of oerdnj from a similar post, I confirm that

  1. php7.0-mysql package is installed
  2. mysqli appears in phpinfo. Below is the result of phpinfo | grep mysqli
  3. and listed below is the output for the ldd command

php -r 'phpinfo();' | grep -i mysqli /etc/php/7.0/cli/conf.d/20-mysqli.ini, mysqli MysqlI Support => enabled mysqli.allow_local_infile => On => On mysqli.allow_persistent => On => On mysqli.default_host => no value => no value mysqli.default_port => 3306 => 3306 mysqli.default_pw => no value => no value mysqli.default_socket => no value => no value mysqli.default_user => no value => no value mysqli.max_links => Unlimited => Unlimited mysqli.max_persistent => Unlimited => Unlimited mysqli.reconnect => Off => Off mysqli.rollback_on_cached_plink => Off => Off API Extensions => mysqli,pdo_mysql

ldd /usr/lib/php/*/mysqli.so linux-vdso.so.1 => (0x00007ffc807a9000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6cde88a000) /lib64/ld-linux-x86-64.so.2 (0x000055a1af509000)

Please help.

2 Answers2

1

PHP offers multiple interfaces to interact with MySQL. One of those interfaces, the one containing functions like mysql_connect(), mysql_query() etc., has been marked as deprecated (meaning "this is outdated, don't use it anymore") for years and years. With the release of PHP 7, those old functions have finally been removed from PHP.

It looks like your database layer is using those outdated and now removed functions. You should replace them with one of the newer interfaces to MySQL that PHP offers, like mysqli or pdo.

0

I changed $conninfo = "mysql://xxxx:ppppp@localhost/ddddd"; to $conninfo = "mysqli://xxxx:ppppp@localhost/ddddd"; and now it works. I don't understand why mysql worked in php5 but not in php7

terdon
  • 100,812