X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdba.php;h=c7b598f2d68e09ed2f3a9ead81d25d23f00d7265;hb=fd3cf1cd02b57e9796e5537dbee468d1c8048a48;hp=86a3762b44f041945891eca407e5e31269fd7b77;hpb=1218e2f88581a3051225318cb7851a0b75a4b0b3;p=friendica.git diff --git a/include/dba.php b/include/dba.php index 86a3762b44..c7b598f2d6 100644 --- a/include/dba.php +++ b/include/dba.php @@ -108,6 +108,23 @@ class dba { return $return; } + /** + * @brief Returns the number of rows + * + * @return string + */ + public function num_rows() { + if (!$this->result) + return 0; + + if ($this->mysqli) { + $return = $this->result->num_rows; + } else { + $return = mysql_num_rows($this->result); + } + return $return; + } + public function q($sql, $onlyquery = false) { global $a; @@ -126,6 +143,8 @@ class dba { $stamp1 = microtime(true); + $sql = "/*".$a->callstack()." */ ".$sql; + if($this->mysqli) $result = @$this->db->query($sql); else @@ -343,6 +362,42 @@ function q($sql) { }} +/** + * @brief Performs a query with "dirty reads" + * + * By doing dirty reads (reading uncommitted data) no locks are performed + * This function can be used to fetch data that doesn't need to be reliable. + * + * @param $args Query parameters (1 to N parameters of different types) + * @return array Query array + */ +function qu($sql) { + + global $db; + $args = func_get_args(); + unset($args[0]); + + if($db && $db->connected) { + $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;"); + $retval = $db->q($stmt); + $db->q("COMMIT;"); + return $retval; + } + + /** + * + * This will happen occasionally trying to store the + * session data after abnormal program termination + * + */ + logger('dba: no database: ' . print_r($args,true)); + return false; + +} + /** * * Raw db query, no arguments