class XDB
{
- public static $connec = null;
- var $_trace_data = array();
+ private static $mysqli = null;
+
+ public static function connect($host, $user, $pwd, $db, $charset = 'utf8', $debug = 0)
+ {
+ XDB::$mysqli = new mysqli($host, $user, $pwd, $db);
+ if (mysqli_connect_errno() && $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);
+ return true;
+ }
public static function _prepare($args)
{
if ($globals->debug & 1) {
$explain = array();
if (strpos($query, 'FOUND_ROWS()') === false) {
- $_res = mysqli_query(XDB::$connec, "EXPLAIN $query");
- if ($_res) {
- while ($row = mysqli_fetch_assoc($_res)) {
+ $res = XDB::$mysqli->query("EXPLAIN $query");
+ if ($res) {
+ while ($row = $res->fetch_assoc()) {
$explain[] = $row;
}
- @mysqli_free_result($_res);
+ $res->free();
}
}
$trace_data = array('query' => XDB::_reformatQuery($query), 'explain' => $explain);
$time_start = microtime();
}
- $res = mysqli_query(XDB::$connec, $query);
+ $res = XDB::$mysqli->query($query);
if ($globals->debug & 1) {
list($ue, $se) = explode(" ", microtime());
list($us, $ss) = explode(" ", $time_start);
$time = intval((($ue - $us) + ($se - $ss)) * 1000);
- $trace_data['error'] = mysqli_error(XDB::$connec);
+ $trace_data['error'] = XDB::$mysqli->error;
$trace_data['exectime'] = $time;
- $trace_data['rows'] = @mysqli_num_rows($res) ? mysqli_num_rows($res) : mysqli_affected_rows(XDB::$connec);
+ $trace_data['rows'] = @$res->num_rows ? $res->num_rows : XDB::$mysqli->affected_rows;
$GLOBALS['XDB::trace_data'][] = $trace_data;
- if (mysqli_errno(XDB::$connec)) {
+ if (XDB::$mysqli->errno) {
$GLOBALS['XDB::error'] = true;
}
}
-
return $res;
}
public static function insertId()
{
- return mysqli_insert_id(XDB::$connec);
+ return XDB::$mysqli->insert_id;
}
public static function _db_escape($var)
class XOrgDBResult
{
- var $_res;
+ private $_res;
function XOrgDBResult($query)
{
function free()
{
- mysqli_free_result($this->_res);
+ $this->_res->free();
unset($this);
}
function _fetchRow()
{
- return mysqli_fetch_row($this->_res);
+ return $this->_res->fetch_row();
}
function _fetchAssoc()
{
- return mysqli_fetch_assoc($this->_res);
+ return $this->_res->fetch_assoc();
}
function fetchAllRow()
{
$result = Array();
- while ($result[] = mysqli_fetch_row($this->_res)) { }
+ while ($result[] = $this->_res->fetch_row());
array_pop($result);
$this->free();
return $result;
function fetchAllAssoc()
{
$result = Array();
- while ($result[] = mysqli_fetch_assoc($this->_res)) { }
+ while ($result[] = $this->_res->fetch_assoc());
array_pop($result);
$this->free();
return $result;
function numRows()
{
- return mysqli_num_rows($this->_res);
+ return $this->_res->num_rows;
}
}
$this->spoolroot = dirname(dirname(__FILE__));
$this->read_config();
-
- $this->dbconnect();
$this->setlocale();
+
+ require_once dirname(__FILE__) . '/../classes/xdb.php';
+ XDB::connect($this->dbhost, $this->dbuser, $this->dbpwd, $this->dbdb, 'utf8', $this->debug);
}
function read_ini_file($filename)
$this->read_ini_file($this->spoolroot.'/configs/platal.conf');
}
- function dbconnect()
- {
- XDB::$connec = @mysqli_connect($this->dbhost, $this->dbuser, $this->dbpwd);
- @mysqli_select_db(XDB::$connec, $this->dbdb);
- mysqli_set_charset(XDB::$connec, 'utf8');
- }
-
function setlocale()
{
setlocale(LC_MESSAGES, $this->locale);