Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /** [Draft] PrestaShop Multi connection
- * Put this file in the /override/classes directory
- *
- * If we need to use a different database with different username (or host),
- * This class allows to make a second mysql connection (and more if you need).
- *
- *
- * Usage :
- * $db1 = new MySQL2(_DB_SERVER_, _DB_USER_, _DB_PASSWD_, 'dbname1', true);
- * $db2 = new MySQL2('1.2.3.4', 'un_utilisateur', 'un_mot_de_passe', 'le_nom_de_la_bdd', true);
- *
- * Notice : Strict Standards php warning can appear because __construct
- * and connect methods have an extra parameter
- */
- class MySQL2 extends MySQLCore
- {
- public function __construct($server, $user, $password, $database, $newlink = false)
- {
- $this->_server = $server;
- $this->_user = $user;
- $this->_password = $password;
- $this->_type = _DB_TYPE_;
- $this->_database = $database;
- $this->connect($newlink);
- }
- public function connect($newlink = false)
- {
- if (!defined('_PS_DEBUG_SQL_'))
- define('_PS_DEBUG_SQL_', false);
- if ($this->_link = mysql_connect($this->_server, $this->_user, $this->_password, $newlink))
- {
- if(!$this->set_db($this->_database))
- die(Tools::displayError('The database selection cannot be made.'));
- }
- else
- die(Tools::displayError('Link to database cannot be established.'));
- /* UTF-8 support */
- if (!mysql_query('SET NAMES \'utf8\'', $this->_link))
- die(Tools::displayError('PrestaShop Fatal error: no utf-8 support. Please check your server configuration.'));
- // removed SET GLOBAL SQL_MODE : we can't do that (see PSCFI-1548)
- return $this->_link;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment