Menu

error: php7 mysql connect()

Developers
Maxim
2015-11-11
2016-01-25
  • Maxim

    Maxim - 2015-11-11

    PHP 7 output error: declaration should be compatible with mysqli::connect

    Did not found other method for pull request. Here my patch (+ small modification of .gitignore):

    From a07791c0c03ca2c93d81d47ee0aebb2573ccf234 Mon Sep 17 00:00:00 2001
    From: Maxim
    Date: Tue, 20 Oct 2015 12:20:21 +0300
    Subject: [PATCH 1/2] Fix PHP7 warning with Min_DB:connect() declaration
    
    ---
     adminer/drivers/mysql.inc.php | 20 ++++++++++++++------
     1 file changed, 14 insertions(+), 6 deletions(-)
    
    diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php
    index 51aa407..faf96a2 100644
    --- a/adminer/drivers/mysql.inc.php
    +++ b/adminer/drivers/mysql.inc.php
    @@ -13,16 +13,24 @@ if (!defined("DRIVER")) {
                    parent::init();
                }
    
    -           function connect($server, $username, $password) {
    +           function connect($server = NULL, $username = NULL, $password = NULL, $database = NULL, $port = NULL, $socket = NULL) {      // PHP 7: declaration should be compatible with mysqli::connect
                    mysqli_report(MYSQLI_REPORT_OFF); // stays between requests, not required since PHP 5.3.4
    -               list($host, $port) = explode(":", $server, 2); // part after : is used for port or socket
    +               if (strpos($server, ":"))
    +               {
    +                   list($host, $port) = explode(":", $server, 2); // part after : is used for port or socket
    +                   if (!is_numeric($port))
    +                       $socket = $port;
    +               }
    +               else
    +                   $host = $server;
    +
                    $return = @$this->real_connect(
    -                   ($server != "" ? $host : ini_get("mysqli.default_host")),
    +                   ($host != "" ? $host : ini_get("mysqli.default_host")),
                        ($server . $username != "" ? $username : ini_get("mysqli.default_user")),
                        ($server . $username . $password != "" ? $password : ini_get("mysqli.default_pw")),
    -                   null,
    +                   $database,
                        (is_numeric($port) ? $port : ini_get("mysqli.default_port")),
    -                   (!is_numeric($port) ? $port : null)
    +                   (is_string($socket) ? $socket : null)
                    );
                    return $return;
                }
    @@ -44,7 +52,7 @@ if (!defined("DRIVER")) {
                    $row = $result->fetch_array();
                    return $row[$field];
                }
    -           
    +
                function quote($string) {
                    return "'" . $this->escape_string($string) . "'";
                }
    -- 
    1.9.5.github.0
    
    From ea1909c8d46c1c7e4fa85b4d0fead5b1b7eb8107 Mon Sep 17 00:00:00 2001
    From: Maxim
    Date: Wed, 11 Nov 2015 11:42:57 +0200
    Subject: [PATCH 2/2] modify gitignore
    
    add possibility to access to dev adminer root dir from web
    ---
     .gitignore | 2 ++
     1 file changed, 2 insertions(+)
    
    diff --git a/.gitignore b/.gitignore
    index 2afb1ac..8629781 100644
    --- a/.gitignore
    +++ b/.gitignore
    @@ -2,3 +2,5 @@
     /adminer*.php
     /editor*.php
     /vendor/
    +/index.php
    +/adminer.css
    -- 
    1.9.5.github.0
    
     

    Last edit: Maxim 2015-11-11
  • Maxim

    Maxim - 2015-11-12

    Made pull request on GitHub. This topic can be deleted.

     
  • Jakub Vrána

    Jakub Vrána - 2016-01-25

    Fixed in Git, thanks.

     

Log in to post a comment.