return $sql;
}
+ /**
+ * @brief Convert parameter array to an universal form
+ * @param array $args Parameter array
+ * @return array universalized parameter array
+ */
+ private static function getParam($args) {
+ unset($args[0]);
+
+ // When the second function parameter is an array then use this as the parameter array
+ if ((count($args) > 0) && (is_array($args[1]))) {
+ return $args[1];
+ } else {
+ return $args;
+ }
+ }
+
/**
* @brief Executes a prepared statement that returns data
* @usage Example: $r = p("SELECT * FROM `item` WHERE `guid` = ?", $guid);
$stamp1 = microtime(true);
- $args = func_get_args();
- unset($args[0]);
-
- // When the second function parameter is an array then use this as the parameter array
- if ((count($args) > 0) && (is_array($args[1]))) {
- $params = $args[1];
- } else {
- $params = $args;
- }
+ $params = self::getParam(func_get_args());
// Renumber the array keys to be sure that they fit
$i = 0;
self::$dbo->affected_rows = 0;
// We have to make some things different if this function is called from "e"
- $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
+ $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
- if (isset($trace[2])) {
- $called_from = $trace[2];
+ if (isset($trace[1])) {
+ $called_from = $trace[1];
} else {
// We use just something that is defined to avoid warnings
$called_from = $trace[0];
$stamp = microtime(true);
- $args = func_get_args();
+ $params = self::getParam(func_get_args());
// In a case of a deadlock we are repeating the query 20 times
$timeout = 20;
do {
- $stmt = call_user_func_array('self::p', $args);
+ $stmt = self::p($sql, $params);
if (is_bool($stmt)) {
$retval = $stmt;
$error = self::$dbo->error;
$errorno = self::$dbo->errorno;
- array_shift($args);
-
- // When the second function parameter is an array then use this as the parameter array
- if ((count($args) > 0) && (is_array($args[0]))) {
- $params = $args[0];
- } else {
- $params = $args;
- }
-
logger('DB Error '.self::$dbo->errorno.': '.self::$dbo->error."\n".
$a->callstack(8)."\n".self::replace_parameters($sql, $params));
* @return boolean Are there rows for that query?
*/
static public function exists($sql) {
- $args = func_get_args();
+ $params = self::getParam(func_get_args());
- $stmt = call_user_func_array('self::p', $args);
+ $stmt = self::p($sql, $params);
if (is_bool($stmt)) {
$retval = $stmt;
* @return array first row of query
*/
static public function fetch_first($sql) {
- $args = func_get_args();
+ $params = self::getParam(func_get_args());
- $stmt = call_user_func_array('self::p', $args);
+ $stmt = self::p($sql, $params);
if (is_bool($stmt)) {
$retval = $stmt;