X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdba_pdo.php;h=9f2774d9b78c2f85230ed61717a7ca8c4ad7003d;hb=0cd9db9cb7f4c96f597e37590a536eaae123238d;hp=63f35739a36bac973d5914ac794d86339dea87ab;hpb=79d524a9ad6319bbf82e2e826c36fa024c60bc41;p=friendica.git diff --git a/include/dba_pdo.php b/include/dba_pdo.php index 63f35739a3..9f2774d9b7 100644 --- a/include/dba_pdo.php +++ b/include/dba_pdo.php @@ -14,18 +14,19 @@ $objDDDBLResultHandler = new DataObjectPool('Result-Handler'); * **/ $cloPDOStatementResultHandler = function(Queue $objQueue) { + $objPDO = $objQueue->getState()->get('PDOStatement'); + $objQueue->getState()->update(array('result' => $objPDO)); - $objPDO = $objQueue->getState()->get('PDOStatement'); - $objQueue->getState()->update(array('result' => $objPDO)); - - # delete handler which closes the PDOStatement-cursor - # this will be done manual if using this handler - $objQueue->deleteHandler(QUEUE_CLOSE_CURSOR_POSITION); - + /* + * delete handler which closes the PDOStatement-cursor + * this will be done manual if using this handler + */ + $objQueue->deleteHandler(QUEUE_CLOSE_CURSOR_POSITION); }; $objDDDBLResultHandler->add('PDOStatement', array('HANDLER' => $cloPDOStatementResultHandler)); +if (! class_exists('dba')) { /** * * MySQL database class @@ -36,8 +37,6 @@ $objDDDBLResultHandler->add('PDOStatement', array('HANDLER' => $cloPDOStatementR * the debugging stream is safe to view within both terminals and web pages. * */ - -if (! class_exists('dba')) { class dba { private $debug = 0; @@ -146,16 +145,17 @@ class dba { $a->save_timestamp($stamp1, "database"); - /// @TODO really check $a->config for 'system'? it is very generic and should be there - if (x($a->config, 'system') && x($a->config['system'], 'db_log')) { - if (($duration > $a->config["system"]["db_loglimit"])) { - $duration = round($duration, 3); - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - @file_put_contents($a->config["system"]["db_log"], datetime_convert()."\t".$duration."\t". - basename($backtrace[1]["file"])."\t". - $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t". - substr($sql, 0, 2000)."\n", FILE_APPEND); - } + /* + * Check if the configuration group 'system' and db_log is there. The + * extra first check needs to be done to avoid endless loop. + */ + if (x($a->config, 'system') && x($a->config['system'], 'db_log') && ($duration > $a->config["system"]["db_loglimit"])) { + $duration = round($duration, 3); + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + @file_put_contents($a->config["system"]["db_log"], datetime_convert()."\t".$duration."\t". + basename($backtrace[1]["file"])."\t". + $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t". + substr($sql, 0, 2000)."\n", FILE_APPEND); } if ($intErrorCode) { @@ -190,20 +190,23 @@ class dba { * regardless of any logging that may or may nor be in effect. * These usually indicate SQL syntax errors that need to be resolved. */ - if (isset($result) AND ($result === false)) { + if (isset($result) && ($result === false)) { logger('dba: ' . printable($sql) . ' returned false.' . "\n" . $this->error); if (file_exists('dbfail.out')) { file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND); } } - if (isset($result) AND (($result === true) || ($result === false))) { + if (isset($result) && (($result === true) || ($result === false))) { return $result; } if ($onlyquery) { - $this->result = $r; # this will store an PDOStatement Object in result - $this->result->execute(); # execute the Statement, to get its result + // this will store an PDOStatement Object in result + $this->result = $r; + + // execute the Statement, to get its result + $this->result->execute(); return true; } @@ -262,7 +265,8 @@ function printable($s) { return $s; }} -// Procedural functions +// --- Procedural functions --- + if (! function_exists('dbg')) { function dbg($state) { global $db; @@ -273,18 +277,20 @@ function dbg($state) { if (! function_exists('dbesc')) { function dbesc($str) { global $db; - if ($db && $db->connected) - return($db->escape($str)); - else - return(str_replace("'","\\'",$str)); + + if ($db && $db->connected) { + return $db->escape($str); + } else { + return str_replace("'","\\'",$str); + } }} if (! function_exists('q')) { -/** +/* * Function: q($sql,$args); * Description: execute SQL query with printf style args. * Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d", - * 'user', 1); + * 'user', 1); */ function q($sql) { @@ -301,23 +307,19 @@ function q($sql) { return $db->q($stmt); } - /** - * + /* * This will happen occasionally trying to store the * session data after abnormal program termination - * */ logger('dba: no database: ' . print_r($args,true)); return false; - }} if (! function_exists('dbq')) { -/** +/* * Raw db query, no arguments */ function dbq($sql) { - global $db; if ($db && $db->connected) { $ret = $db->q($sql); @@ -327,15 +329,14 @@ function dbq($sql) { return $ret; }} - -/* - * 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. - */ if (! function_exists('dbesc_array_cb')) { function dbesc_array_cb(&$item, $key) { + /* + * 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. + */ if (is_string($item)) { $item = dbesc($item); }