diff --git a/dibi/dibi.php b/dibi/dibi.php index 7154fc86..a8d69c25 100644 --- a/dibi/dibi.php +++ b/dibi/dibi.php @@ -166,7 +166,7 @@ class dibi * @return DibiDriver * @throws DibiException */ - public static function connect($config, $name = 0) + public static function connect($config = 'driver=mysql', $name = 0) { // DSN string if (is_string($config)) { @@ -192,7 +192,7 @@ class dibi /** like $connection = $class::connect($config); */ self::$connection = self::$registry[$name] = new $class($config); - if (dibi::$logAll) dibi::log("OK: connected to DB '$config[driver]'"); + if (self::$logAll) self::log("OK: connected to DB '$config[driver]'"); return self::$connection; } @@ -460,26 +460,28 @@ class dibi /** * Remove substitution pair * - * @param string from + * @param mixed from or TRUE * @return void */ public static function removeSubst($expr) { - unset(self::$substs[':'.$expr.':']); + if ($expr === TRUE) { + self::$substs = array(); + } else { + unset(self::$substs[':'.$expr.':']); + } } /** - * Process substitutions in string + * Returns substitution pairs * - * @param string - * @return string + * @return array */ - public static function substitute($s) + public static function getSubst() { - if (strpos($s, ':') === FALSE) return $s; - return strtr($s, self::$substs); + return self::$substs; } diff --git a/dibi/libs/translator.php b/dibi/libs/translator.php index 77db37c3..55318e96 100644 --- a/dibi/libs/translator.php +++ b/dibi/libs/translator.php @@ -116,8 +116,8 @@ final class DibiTranslator // TODO: check !!! $sql = preg_replace('#\x00.*?\x00#s', '', $sql); - // error handling if ($this->hasError) { + // TODO: do it better, remove dibi::$... if (dibi::$logFile) { // log to file dibi::log( "ERROR: SQL generate error" @@ -402,7 +402,10 @@ final class DibiTranslator */ private function delimite($value) { - return $this->driver->delimite( dibi::substitute($value) ); + if (strpos($value, ':') !== FALSE) { + $value = strtr($value, dibi::getSubst()); + } + return $this->driver->delimite($value); }