Connect to DB on demand
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 4 Feb 2007 14:02:57 +0000 (14:02 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 4 Feb 2007 14:02:57 +0000 (14:02 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1477 839d8a87-29fc-0310-9880-83ba4fa771e5

classes/xdb.php
include/globals.inc.php.in

index 7301ebd..35f455f 100644 (file)
@@ -23,17 +23,18 @@ class XDB
 {
     private static $mysqli = null;
 
-    public static function connect($host, $user, $pwd, $db, $charset = 'utf8', $debug = 0)
+    public static function connect()
     {
-        XDB::$mysqli = new mysqli($host, $user, $pwd, $db);
-        if (mysqli_connect_errno() && $debug & 1) {
+        global $globals;
+        XDB::$mysqli = new mysqli($globals->dbhost, $globals->dbuser, $globals->dbpwd, $globals->dbdb);
+        if (mysqli_connect_errno() && $globals->debug & 1) {
             $GLOBALS['XDB::trace_data'][] = array('query' => 'MySQLI connection', 'explain' => array(),
                                                   'error' => mysqli_connect_error(), 'exectime' => 0, 'rows' => 0);
             $GLOBALS['XDB::error'] = true;
             return false;
         }
         XDB::$mysqli->autocommit(true);
-        XDB::$mysqli->set_charset($charset);
+        XDB::$mysqli->set_charset($globals->dbcharset);
         return true;
     }
 
@@ -73,6 +74,10 @@ class XDB
     {
         global $globals;
 
+        if (!XDB::$mysqli && !XDB::connect()) {
+            return false;
+        }
+
         if ($globals->debug & 1) {
             $explain = array();
             if (strpos($query, 'FOUND_ROWS()') === false) {
index 74fb56c..31a5760 100644 (file)
@@ -32,6 +32,7 @@ class PlatalGlobals
     var $dbhost             = 'localhost';
     var $dbuser             = 'x4dat';
     var $dbpwd              = 'x4dat';
+    var $dbcharset          = 'utf8';
 
     /** paths */
     var $baseurl;
@@ -50,8 +51,6 @@ class PlatalGlobals
 
         $this->read_config();
         $this->setlocale();
-
-        XDB::connect($this->dbhost, $this->dbuser, $this->dbpwd, $this->dbdb, 'utf8', $this->debug);
     }
 
     function read_ini_file($filename)