Jump to content

Autoupgrade Bug "invalid Database Configuration" Adminselfupgrade.php


omine

Recommended Posts

I was having problem to upgrade PrestaShop since 1.6.1.1.

 

The upgrade process was being interrupted with message 'Invalid database configuration.'

 

Mitigating the problem, i found the reson on this file:

 

/modules/autoupgrade/AdminSelfUpgrade.php

 

The original code with my personal comments:

//check DB access
$this->db; // <--  this should be here? seems a mistyping.
error_reporting(E_ALL);
$resultDB = Db::checkConnection(_DB_SERVER_, _DB_USER_, _DB_PASSWD_, _DB_NAME_);

/**
Disabled to avoid the "Invalid database configuration" error while upgrading the PrestaShop.
The variable $resultDB always returning 1 or different of 0.
*/
/**
if ($resultDB !== 0)
{
    // $logger->logError('Invalid database configuration.');
    $this->next = 'error';
    $this->nextQuickInfo[] = $this->l('Invalid database configuration');
    $this->nextErrors[] = $this->l('Invalid database configuration');
    return false;
}
*/

After disable this code, the upgrade process finished successful.  ;) 

 

 

More detailed information

 

I did search over all PrestaShop files, searching for "Db::checkConnection".

 

The only file using this function is "AdminSelfUpgrade.php".

 

I think this should be removed or fixed for next releases.

 

 

Db::checkConnection invokes call_user_func_array() which in turn, calls the database library dynamically.

    public static function checkConnection($server, $user, $pwd, $db, $new_db_link = true, $engine = null, $timeout = 5)
    {
        return call_user_func_array(array(Db::getClass(), 'tryToConnect'), array($server, $user, $pwd, $db, $new_db_link, $engine, $timeout));
    }

The library is returned by Db::getClass()

 

    public static function getClass()
    {
        $class = 'MySQL';
        if (PHP_VERSION_ID >= 50200 && extension_loaded('pdo_mysql')) {
            $class = 'DbPDO';
        } elseif (extension_loaded('mysqli')) {
            $class = 'DbMySQLi';
        }


        return $class;
    }

This code returns different value on this same server.

From BackOffice, returns DbMySQLi

 

Howeverrunning the same script outside PrestaShop, on same server, returns DbPDO

 

The PHP_VERSION_ID is 50528 and extension_loaded('pdo_mysql') returns boolean true.

So, i don't understand why within PrestaShop BackOffice returning DbMySQLi.

 

 

By the way, DbMySQLi::tryToConnect() code is:
 

    public static function tryToConnect($server, $user, $pwd, $db, $new_db_link = true, $engine = null, $timeout = 5)
    {
        $link = mysqli_init();
        if (!$link) {
            return -1;
        }


        if (!$link->options(MYSQLI_OPT_CONNECT_TIMEOUT, $timeout)) {
            return 1;
        }


        // There is an @ because mysqli throw a warning when the database does not exists
        if (!@$link->real_connect($server, $user, $pwd, $db)) {
            return (mysqli_connect_errno() == 1049) ? 2 : 1;
        }


        $link->close();
        return 0;
    }

The problem may be something on this method. 

 

 

Whatever, the simplest way was skip the $resultDB = Db::checkConnection to complete the upgrade.

If someone face the same issue, this information can be useful.

 

 

 

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
  • 4 weeks later...
  • 4 weeks later...
  • 4 months later...
  • 1 month later...
  • 9 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...