$this->adapter = new Db_Pgsql();
break;
default:
- user_error("Unknown DB_TYPE: " . DB_TYPE);
+ die("Unknown DB_TYPE: " . DB_TYPE);
}
$this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT);
-
}
private function __clone() {
return("'$str'");
}
- function init() {
- //
- }
-
function connect($host, $user, $pass, $db, $port) {
//return $this->adapter->connect($host, $user, $pass, $db, $port);
return $this->link;
function query($query, $die_on_error = true) {
$result = mysql_query($query, $this->link);
if (!$result) {
- $query = htmlspecialchars($query);
- if ($die_on_error) {
- die("Query <i>$query</i> failed: " . ($this->link ? mysql_error($link) : "No connection"));
- }
+ user_error("Query $query failed: " . ($this->link ? mysql_error($this->link) : "No connection"),
+ $die_on_error ? E_USER_ERROR : E_USER_WARNING);
}
return $result;
}
if (!$result) {
$query = htmlspecialchars($query); // just in case
- if ($die_on_error) {
- die("Query <i>$query</i> failed [$result]: " . ($this->link ? pg_last_error($this->link) : "No connection"));
- }
+ user_error("Query $query failed: " . ($this->link ? pg_last_error($this->link) : "No connection"),
+ $die_on_error ? E_USER_ERROR : E_USER_WARNING);
}
return $result;
}
<?php
interface IDb {
function connect($host, $user, $pass, $db, $port);
- function init();
function escape_string($s, $strip_tags = true);
function query($query, $die_on_error = true);
function fetch_assoc($result);
if ($errno == E_NOTICE) return false;
if (Db::get()) {
+
$errno = Db::get()->escape_string($errno);
$errstr = Db::get()->escape_string($errstr);
$file = Db::get()->escape_string($file);
($errno, '$errstr', '$file', '$line', '$context', $owner_uid, NOW())");
return Db::get()->affected_rows($result) != 0;
-
}
+
return false;
}
<?php
// TODO: make configurable
-//require_once "classes/logger.php";
-//require_once "classes/logger/sql.php";
+require_once "classes/logger.php";
+require_once "classes/logger/sql.php";
function ttrss_error_handler($errno, $errstr, $file, $line, $context) {
global $logger;
if (!$logger) $logger = new Logger_SQL();
if ($logger) {
- $logger->log_error($errno, $errstr, $file, $line, $context);
+ if ($logger->log_error($errno, $errstr, $file, $line, $context)) {
+ return true;
+ }
}
+ return false;
}
+
+ return false;
}
-//register_shutdown_function('ttrss_fatal_handler');
-//set_error_handler('ttrss_error_handler');
+register_shutdown_function('ttrss_fatal_handler');
+set_error_handler('ttrss_error_handler');
?>