X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdba.php;h=97f6c8795645492aeda5f47cd5707dc0b325545a;hb=fa33f94b29a9eef1e8e84adcb4dfa7458123a1c5;hp=7409ec3a8ce69e278e9ac0c205dc7890b5e9657e;hpb=1a5da0ae60b2be930e4cd76b28e34aeb550935f0;p=friendica.git diff --git a/include/dba.php b/include/dba.php index 7409ec3a8c..97f6c87956 100644 --- a/include/dba.php +++ b/include/dba.php @@ -1,25 +1,30 @@ connected = true; } + if (isset($a->config["system"]["db_charset"])) + $this->db->set_charset($a->config["system"]["db_charset"]); } else { $this->mysqli = false; @@ -68,6 +75,8 @@ class dba { if($this->db && mysql_select_db($db,$this->db)) { $this->connected = true; } + if (isset($a->config["system"]["db_charset"])) + mysql_set_charset($a->config["system"]["db_charset"], $this->db); } if(! $this->connected) { $this->db = null; @@ -90,6 +99,14 @@ class dba { $this->error = ''; + // Check the connection (This can reconnect the connection - if configured) + if ($this->mysqli) + $connected = $this->db->ping(); + else + $connected = mysql_ping($this->db); + + $connstr = ($connected ? "Connected": "Disonnected"); + $stamp1 = microtime(true); if($this->mysqli) @@ -102,6 +119,9 @@ class dba { $a->save_timestamp($stamp1, "database"); + if (strtolower(substr($sql, 0, 6)) != "select") + $a->save_timestamp($stamp1, "database_write"); + if(x($a->config,'system') && x($a->config['system'],'db_log')) { if (($duration > $a->config["system"]["db_loglimit"])) { $duration = round($duration, 3); @@ -114,14 +134,17 @@ class dba { } if($this->mysqli) { - if($this->db->errno) + if($this->db->errno) { $this->error = $this->db->error; + $this->errorno = $this->db->errno; + } + } elseif(mysql_errno($this->db)) { + $this->error = mysql_error($this->db); + $this->errorno = mysql_errno($this->db); } - elseif(mysql_errno($this->db)) - $this->error = mysql_error($this->db); if(strlen($this->error)) { - logger('dba: ' . $this->error); + logger('DB Error ('.$connstr.') '.$this->errorno.': '.$this->error); } if($this->debug) { @@ -226,8 +249,17 @@ class dba { } } + function connected() { + if ($this->mysqli) + $connected = $this->db->ping(); + else + $connected = mysql_ping($this->db); + + return $connected; + } + function __destruct() { - if ($this->db) + if ($this->db) if($this->mysqli) $this->db->close(); else @@ -245,14 +277,14 @@ function printable($s) { }} // Procedural functions -if(! function_exists('dbg')) { +if(! function_exists('dbg')) { function dbg($state) { global $db; if($db) $db->dbg($state); }} -if(! function_exists('dbesc')) { +if(! function_exists('dbesc')) { function dbesc($str) { global $db; if($db && $db->connected) @@ -268,7 +300,7 @@ function dbesc($str) { // Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d", // 'user', 1); -if(! function_exists('q')) { +if(! function_exists('q')) { function q($sql) { global $db; @@ -285,12 +317,12 @@ function q($sql) { /** * - * This will happen occasionally trying to store the - * session data after abnormal program termination + * This will happen occasionally trying to store the + * session data after abnormal program termination * */ logger('dba: no database: ' . print_r($args,true)); - return false; + return false; }} @@ -300,7 +332,7 @@ function q($sql) { * */ -if(! function_exists('dbq')) { +if(! function_exists('dbq')) { function dbq($sql) { global $db; @@ -312,10 +344,10 @@ function dbq($sql) { }} -// Caller is responsible for ensuring that any integer arguments to +// Caller is responsible for ensuring that any integer arguments to // dbesc_array are actually integers and not malformed strings containing -// SQL injection vectors. All integer array elements should be specifically -// cast to int to avoid trouble. +// SQL injection vectors. All integer array elements should be specifically +// cast to int to avoid trouble. if(! function_exists('dbesc_array_cb')) { @@ -336,4 +368,3 @@ function dbesc_array(&$arr) { function dba_timer() { return microtime(true); } -