sql logger: pdo

This commit is contained in:
Andrew Dolgov 2017-12-02 00:13:28 +03:00
parent c1c08aed39
commit 4102eb843f
1 changed files with 9 additions and 12 deletions

View File

@ -2,22 +2,19 @@
class Logger_SQL { class Logger_SQL {
function log_error($errno, $errstr, $file, $line, $context) { function log_error($errno, $errstr, $file, $line, $context) {
if (Db::get() && get_schema_version() > 117) {
$errno = Db::get()->escape_string($errno); $pdo = Db::pdo();
$errstr = Db::get()->escape_string($errstr);
$file = Db::get()->escape_string($file);
$line = Db::get()->escape_string($line);
$context = DB::get()->escape_string($context);
$owner_uid = $_SESSION["uid"] ? $_SESSION["uid"] : "NULL"; if ($pdo && get_schema_version() > 117) {
$result = Db::get()->query( $owner_uid = $_SESSION["uid"] ? $_SESSION["uid"] : null;
"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, 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; return false;