Index: trunk/core/kernel/db/db_connection.php =================================================================== diff -u -N -r944 -r1339 --- trunk/core/kernel/db/db_connection.php (.../db_connection.php) (revision 944) +++ trunk/core/kernel/db/db_connection.php (.../db_connection.php) (revision 1339) @@ -4,7 +4,7 @@ * Multi database connection class * */ - class DBConnection { + class kDBConnection { /** * Current database type @@ -75,7 +75,7 @@ * @return DBConnection * @access public */ - function DBConnection($dbType, $errorHandler = '') + function kDBConnection($dbType, $errorHandler = '') { $this->dbType = $dbType; $this->initMetaFunctions(); @@ -168,17 +168,24 @@ * @param string $db * @access public */ - function Connect($host,$user,$pass,$db) + function Connect($host,$user,$pass,$db,$force_new=false) { $func = $this->getMetaFunction('connect'); - $this->connectionID = $func($host,$user,$pass) or die('Can\'t connect to db'); + $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) + { + $func = $this->getMetaFunction('close'); + $func($this->connectionID); + $this->Connect($host,$user,$pass,$db); + } + /** * Shows error message from previous operation * if it failed @@ -269,7 +276,7 @@ { $sql .= ' '.$this->getLimitClause(0,1); $ret = $this->Query($sql); - if(!$ret) return $ret; + if(!$ret) return false; return array_shift($ret); } @@ -482,18 +489,32 @@ */ function qstr($s,$magic_quotes=false) { - $replace_quote = "\\'"; + $replaceQuote = "\\'"; if (!$magic_quotes) { - return "'".str_replace("'",$replace_quote,$s)."'"; + if ($replaceQuote[0] == '\\') + { + // only since php 4.0.5 + $s = str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s); + //$s = str_replace("\0","\\\0", str_replace('\\','\\\\',$s)); + } + return "'".str_replace("'",$replaceQuote,$s)."'"; } // undo magic quotes for " $s = str_replace('\\"','"',$s); - return "'$s'"; + + if($replaceQuote == "\\'") // ' already quoted, no need to change anything + { + return "'$s'"; + } + else // change \' to '' for sybase/mssql + { + $s = str_replace('\\\\','\\',$s); + return "'".str_replace("\\'",$replaceQuote,$s)."'"; + } } - /** * Returns last error message *