michael-marinetti

[Draft] PrestaShop Multi connection

Aug 5th, 2011
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <?php
  2.  
  3. /** [Draft] PrestaShop Multi connection
  4. * Put this file in the /override/classes directory
  5. *
  6. * If we need to use a different database with different username (or host),
  7. * This class allows to make a second mysql connection (and more if you need).
  8. *
  9. *
  10. * Usage :
  11. * $db1 = new MySQL2(_DB_SERVER_, _DB_USER_, _DB_PASSWD_, 'dbname1', true);
  12. * $db2 = new MySQL2('1.2.3.4', 'un_utilisateur', 'un_mot_de_passe', 'le_nom_de_la_bdd', true);
  13. *
  14. * Notice : Strict Standards php warning can appear because __construct
  15. * and connect methods have an extra parameter
  16. */
  17. class MySQL2 extends MySQLCore
  18.  
  19. {
  20.  
  21.     public function __construct($server, $user, $password, $database, $newlink = false)
  22.     {
  23.         $this->_server = $server;
  24.         $this->_user = $user;
  25.         $this->_password = $password;
  26.         $this->_type = _DB_TYPE_;
  27.         $this->_database = $database;
  28.  
  29.         $this->connect($newlink);
  30.     }
  31.  
  32.     public function connect($newlink = false)
  33.     {
  34.         if (!defined('_PS_DEBUG_SQL_'))
  35.             define('_PS_DEBUG_SQL_', false);
  36.         if ($this->_link = mysql_connect($this->_server, $this->_user, $this->_password, $newlink))
  37.         {
  38.             if(!$this->set_db($this->_database))
  39.                 die(Tools::displayError('The database selection cannot be made.'));
  40.         }
  41.         else
  42.             die(Tools::displayError('Link to database cannot be established.'));
  43.         /* UTF-8 support */
  44.         if (!mysql_query('SET NAMES \'utf8\'', $this->_link))
  45.             die(Tools::displayError('PrestaShop Fatal error: no utf-8 support. Please check your server configuration.'));
  46.         // removed SET GLOBAL SQL_MODE : we can't do that (see PSCFI-1548)
  47.         return $this->_link;
  48.     }
  49. }
  50.  
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment