Index: trunk/core/kernel/db/db_connection.php =================================================================== diff -u -N -r4840 -r5096 --- trunk/core/kernel/db/db_connection.php (.../db_connection.php) (revision 4840) +++ trunk/core/kernel/db/db_connection.php (.../db_connection.php) (revision 5096) @@ -13,20 +13,23 @@ * @access private */ var $dbType = 'mysql'; + /** * Created connection handle * * @var resource * @access private */ var $connectionID = null; + /** * Handle of currenty processed recordset * * @var resource * @access private */ var $queryID = null; + /** * DB type specific function mappings * @@ -50,6 +53,7 @@ * @access private */ var $errorCode = 0; + /** * Error message * @@ -65,7 +69,7 @@ * * @var bool */ - var $debugMode=false; + var $debugMode = false; /** * Last query to database @@ -85,13 +89,11 @@ function kDBConnection($dbType, $errorHandler = '') { $this->dbType = $dbType; - $this->initMetaFunctions(); - if(!$errorHandler) - { - $this->errorHandler = Array(&$this,'handleError'); +// $this->initMetaFunctions(); + if (!$errorHandler) { + $this->errorHandler = Array(&$this, 'handleError'); } - else - { + else { $this->errorHandler=$errorHandler; } } @@ -103,10 +105,10 @@ * @param string $msg * @access public */ - function setError($code,$msg) + function setError($code, $msg) { - $this->errorCode=$code; - $this->errorMessage=$msg; + $this->errorCode = $code; + $this->errorMessage = $msg; } /** @@ -130,7 +132,7 @@ function initMetaFunctions() { $ret = Array(); - switch($this->dbType) + switch ($this->dbType) { case 'mysql': $ret = Array(); // only define functions, that name differs from "dbType_" @@ -152,15 +154,11 @@ */ function getMetaFunction($name) { - if( !isset($this->metaFunctions[$name]) ) - { - if(function_exists($this->dbType.'_'.$name)) return $this->dbType.'_'.$name; - } - else - { - return $this->dbType.$name; - } - return false; + /*if (!isset($this->metaFunctions[$name])) { + $this->metaFunctions[$name] = $name; + }*/ + + return $this->dbType.'_'.$name; } @@ -175,22 +173,21 @@ * @param string $db * @access public */ - function Connect($host,$user,$pass,$db,$force_new=false) + function Connect($host, $user, $pass, $db, $force_new = false) { $func = $this->getMetaFunction('connect'); - $this->connectionID = $func($host,$user,$pass,$force_new) or die('Can\'t connect to db'); - if($this->connectionID) - { + $this->connectionID = $func($host, $user, $pass, $force_new) or die('Can\'t connect to db'); + if ($this->connectionID) { $this->setDB($db); $this->showError(); } } - function ReConnect($host,$user,$pass,$db) + function ReConnect($host, $user, $pass, $db) { $func = $this->getMetaFunction('close'); $func($this->connectionID); - $this->Connect($host,$user,$pass,$db); + $this->Connect($host, $user, $pass, $db); } /** @@ -199,26 +196,22 @@ * * @access private */ - function showError($sql='') + function showError($sql = '') { - $this->setError(0,''); // reset error - if($this->connectionID) - { + $this->setError(0, ''); // reset error + if ($this->connectionID) { $func = $this->getMetaFunction('errno'); $this->errorCode = $func($this->connectionID); - if($this->hasError()) - { + if ($this->hasError()) { $func = $this->getMetaFunction('error'); $this->errorMessage = $func($this->connectionID); - if(is_array($this->errorHandler)) - { + if (is_array($this->errorHandler)) { $func = $this->errorHandler[1]; - $ret = $this->errorHandler[0]->$func($this->errorCode,$this->errorMessage,$sql); + $ret = $this->errorHandler[0]->$func($this->errorCode, $this->errorMessage, $sql); } - else - { + else { $func = $this->errorHandler; $ret = $func($this->errorCode,$this->errorMessage,$sql); } - if(!$ret) exit; + if (!$ret) exit; } } } @@ -232,7 +225,7 @@ * @return bool * @access private */ - function handleError($code,$msg,$sql) + function handleError($code, $msg, $sql) { echo 'Processing SQL: '.$sql.'
'; echo 'Error ('.$code.'): '.$msg.'
'; @@ -249,7 +242,7 @@ */ function setDB($new_name) { - if(!$this->connectionID) return false; + if (!$this->connectionID) return false; $func = $this->getMetaFunction('select_db'); return $func($new_name); } @@ -305,22 +298,18 @@ function GetCol($sql, $key_field = null) { $rows = $this->Query($sql); - if(!$rows) return $rows; + if (!$rows) return $rows; $i = 0; $row_count = count($rows); $ret = Array(); - if(isset($key_field)) - { - while ($i < $row_count) - { + if (isset($key_field)) { + while ($i < $row_count) { $ret[$rows[$i][$key_field]] = array_shift($rows[$i]); $i++; } } - else - { - while ($i < $row_count) - { + else { + while ($i < $row_count) { $ret[] = array_shift($rows[$i]); $i++; } @@ -339,27 +328,22 @@ * @param string $key_field * @return Array */ - function Query($sql,$key_field = null) + function Query($sql, $key_field = null) { $this->lastQuery = $sql; - if($this->debugMode) return $this->debugQuery($sql,$key_field); + if ($this->debugMode) return $this->debugQuery($sql,$key_field); $query_func = $this->getMetaFunction('query'); $this->queryID = $query_func($sql,$this->connectionID); - if( is_resource($this->queryID) ) - { + if (is_resource($this->queryID)) { $ret = Array(); $fetch_func = $this->getMetaFunction('fetch_assoc'); - if( isset($key_field) ) - { - while( ($row = $fetch_func($this->queryID)) ) - { + if (isset($key_field)) { + while (($row = $fetch_func($this->queryID))) { $ret[$row[$key_field]] = $row; } } - else - { - while( ($row = $fetch_func($this->queryID)) ) - { + else { + while (($row = $fetch_func($this->queryID))) { $ret[] = $row; } } @@ -373,7 +357,7 @@ function ChangeQuery($sql) { $this->Query($sql); - return $this->errorCode==0 ? true : false; + return $this->errorCode == 0 ? true : false; } function debugQuery($sql, $key_field = null) @@ -382,10 +366,9 @@ $query_func = $this->getMetaFunction('query'); // set 1st checkpoint: begin - $isSkipTable=true; - $profileSQLs=defined('DBG_SQL_PROFILE') && DBG_SQL_PROFILE; - if($profileSQLs) - { + $isSkipTable = true; + $profileSQLs = defined('DBG_SQL_PROFILE') && DBG_SQL_PROFILE; + if ($profileSQLs) { $isSkipTable = isSkipTable($sql); if (!$isSkipTable) { $queryID = $debugger->generateID();