Jump to content

Presta on new server with php 5.5 - problem with db connection


Recommended Posts

I just tried to move a latest version of presta from a server with php 5.3 to one with php 5.5 and getting this on new server:

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/shopformbd/public_html/classes/db/MySQL.php on line 37

Warning: Cannot modify header information - headers already sent by (output started at /home/shopformbd/public_html/classes/db/MySQL.php:37) in /home/shopformbd/public_html/classes/shop/Shop.php on line 422

Warning: Cannot modify header information - headers already sent by (output started at /home/shopformbd/public_html/classes/db/MySQL.php:37) in /home/shopformbd/public_html/classes/shop/Shop.php on line 423

My hosting company says:

 

This warning is given because your code is using a deprecated function and it will soon stop being supported by PHP.

The warning given mentions your site code specifically

/home/shopformbd/public_html/classes/db/MySQL.php line 37

The entire ext/mysql PHP extension, which provides all functions named with the prefix mysql_, is officially deprecated as of PHP v5.5.0 and will be removed in the future.

It was originally introduced in PHP v2.0 (November 1997) for MySQL v3.20, and no new features have been added since 2006. Coupled with the lack of new features are difficulties in maintaining such old code amidst complex security vulnerabilities.

As the error message suggests, there are two other MySQL extensions that you can consider: MySQLi and PDO_MySQL, either of which can be used instead of ext/mysql. Both have been in PHP core since v5.0, so if you're using a version that is throwing these deprecation errors then you can almost certainly just start using them right away—i.e. without any installation effort.

They differ slightly, but offer a number of advantages over the old extension including API support for transactions, stored procedures and prepared statements (thereby providing the best way to defeat SQL injection attacks). PHP developer Ulf Wendel has written a thorough comparison of the features.

Hashphp.org has an excellent tutorial on migrating from ext/mysql to PDO.

http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers

 

 

 

 

How to fix it?

Link to comment
Share on other sites

Prestashop will check if either PDO or MySQLI extensions are installed and enabled and use them.  Apparently these are not enabled on your server, so Prestashop reverts to using the deprecated one

    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;
    }

 

Link to comment
Share on other sites

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...