]> git.wh0rd.org - tt-rss.git/blobdiff - classes/logger/sql.php
Logger_SQL: use separate PDO connection
[tt-rss.git] / classes / logger / sql.php
old mode 100644 (file)
new mode 100755 (executable)
index 888ef67..73552c1
@@ -1,31 +1,26 @@
 <?php
 class Logger_SQL {
 
-       function log_error($errno, $errstr, $file, $line, $context) {
+       private $pdo;
 
-               if ($errno == E_NOTICE) return false;
+       function log_error($errno, $errstr, $file, $line, $context) {
 
-               if (Db::get()) {
+               // separate PDO connection object is used for logging
+               if (!$this->pdo) $this->pdo = Db::instance()->pdo_connect();
 
-                       $errno = Db::get()->escape_string($errno);
-                       $errstr = Db::get()->escape_string($errstr);
-                       $file = Db::get()->escape_string($file);
-                       $line = Db::get()->escape_string($line);
-                       $context = ''; // backtrace is a lot of data which is not really critical to store
-                       //$context = db_escape_string(serialize($context));
+               if ($this->pdo && get_schema_version() > 117) {
 
-                       $owner_uid = $_SESSION["uid"] ? $_SESSION["uid"] : "NULL";
+                       $owner_uid = $_SESSION["uid"] ? $_SESSION["uid"] : null;
 
-                       $result = Db::get()->query(
-                               "INSERT INTO ttrss_error_log
+                       $sth = $this->pdo->prepare("INSERT INTO ttrss_error_log
                                (errno, errstr, filename, lineno, context, owner_uid, created_at) VALUES
-                               ($errno, '$errstr', '$file', '$line', '$context', $owner_uid, NOW())");
+                               (?, ?, ?, ?, ?, ?, NOW())");
+                       $sth->execute([$errno, $errstr, $file, $line, $context, $owner_uid]);
 
-                       return Db::get()->affected_rows($result) != 0;
+                       return $sth->rowCount();
                }
 
                return false;
        }
 
 }
-?>