X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdba.php;h=920027cbcfaeef721a02f2ec3214efed0fcf459b;hb=51716957b24d97c20f078d1f880a6ca112cae792;hp=17b8a0a12bffba10ea7569d7c4f66e490170cd7c;hpb=b99f5b576e91bac79abf910aac1bed18312395c0;p=friendica.git diff --git a/include/dba.php b/include/dba.php index 17b8a0a12b..920027cbcf 100644 --- a/include/dba.php +++ b/include/dba.php @@ -35,7 +35,7 @@ class dba { public $error = false; function __construct($server, $user, $pass, $db, $install = false) { - global $a; + $a = get_app(); $stamp1 = microtime(true); @@ -109,6 +109,17 @@ class dba { return $return; } + /** + * @brief Returns the selected database name + * + * @return string + */ + public function database_name() { + $r = $this->q("SELECT DATABASE() AS `db`"); + + return $r[0]['db']; + } + /** * @brief Returns the number of rows * @@ -128,7 +139,7 @@ class dba { } public function q($sql, $onlyquery = false) { - global $a; + $a = get_app(); if (!$this->db || !$this->connected) { return false; @@ -221,13 +232,14 @@ class dba { if ($result === false) { logger('dba: ' . printable($sql) . ' returned false.' . "\n" . $this->error); - if (file_exists('dbfail.out')) + if (file_exists('dbfail.out')) { file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND); + } } - if (($result === true) || ($result === false)) + if (($result === true) || ($result === false)) { return $result; - + } if ($onlyquery) { $this->result = $result; return true; @@ -250,8 +262,9 @@ class dba { //$a->save_timestamp($stamp1, "database"); - if ($this->debug) + if ($this->debug) { logger('dba: ' . printable(print_r($r, true))); + } return($r); } @@ -318,8 +331,9 @@ if (! function_exists('printable')) { function printable($s) { $s = preg_replace("~([\x01-\x08\x0E-\x0F\x10-\x1F\x7F-\xFF])~",".", $s); $s = str_replace("\x00",'.',$s); - if (x($_SERVER,'SERVER_NAME')) + if (x($_SERVER,'SERVER_NAME')) { $s = escape_tags($s); + } return $s; }} @@ -327,8 +341,9 @@ function printable($s) { if (! function_exists('dbg')) { function dbg($state) { global $db; - if ($db) - $db->dbg($state); + if ($db) { + $db->dbg($state); + } }} if (! function_exists('dbesc')) { @@ -393,9 +408,9 @@ function qu($sql) { $stmt = @vsprintf($sql,$args); // Disabled warnings if ($stmt === false) logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true), LOGGER_DEBUG); - $db->q("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;"); + $db->q("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;"); $retval = $db->q($stmt); - $db->q("COMMIT;"); + $db->q("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;"); return $retval; }