From 821744e06ed5c0c6b332682ee81cdc32c0925996 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Sun, 4 Feb 2007 14:02:57 +0000 Subject: [PATCH] Connect to DB on demand git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1477 839d8a87-29fc-0310-9880-83ba4fa771e5 --- classes/xdb.php | 13 +++++++++---- include/globals.inc.php.in | 3 +-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/classes/xdb.php b/classes/xdb.php index 7301ebd..35f455f 100644 --- a/classes/xdb.php +++ b/classes/xdb.php @@ -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) { diff --git a/include/globals.inc.php.in b/include/globals.inc.php.in index 74fb56c..31a5760 100644 --- a/include/globals.inc.php.in +++ b/include/globals.inc.php.in @@ -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) -- 2.1.4