]> git.wh0rd.org - tt-rss.git/blobdiff - classes/logger/sql.php
OPML: use PDO; minor fixes
[tt-rss.git] / classes / logger / sql.php
index a478e8928173eee9c294cedf14c3ccc1af5caede..120584014ce3be33e28eb3adc647528e55b89c7e 100644 (file)
@@ -1,36 +1,29 @@
 <?php
 class Logger_SQL {
 
-       private $link;
-
-       function __construct() {
-               $this->link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
-       }
-
        function log_error($errno, $errstr, $file, $line, $context) {
+               
+               $pdo = Db::pdo();
+               
+               if ($pdo && get_schema_version() > 117) {
 
-               if ($errno == E_NOTICE) return false;
+                       try {
+                               $pdo->rollBack();
+                       } catch (Exception $e) {
+                               //
+                       }
 
-               if ($this->link) {
-                       $errno = db_escape_string($this->link, $errno);
-                       $errstr = db_escape_string($this->link, $errstr);
-                       $file = db_escape_string($this->link, $file);
-                       $line = db_escape_string($this->link, $line);
-                       $context = ''; // backtrace is a lot of data which is not really critical to store
-                       //$context = db_escape_string($this->link, serialize($context));
+                       $owner_uid = $_SESSION["uid"] ? $_SESSION["uid"] : null;
 
-                       $owner_uid = $_SESSION["uid"] ? $_SESSION["uid"] : "NULL";
-
-                       $result = db_query($this->link,
-                               "INSERT INTO ttrss_error_log
+                       $sth = $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())");
-
-                       return db_affected_rows($this->link, $result) != 0;
+                               (?, ?, ?, ?, ?, ?, NOW())");
+                       $sth->execute([$errno, $errstr, $file, $line, $context, $owner_uid]);
 
+                       return $sth->rowCount();
                }
+
                return false;
        }
 
-}
-?>
+}
\ No newline at end of file