function q($sql) { if (!$this->db || !$this->connected) { return false; } $this->error = ''; $result = @mysql_query($sql, $this->db); if (mysql_errno($this->db)) { $this->error = mysql_error($this->db); } if ($result === false || $this->error) { logger('dba_mysql: ' . 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 ($result === true || $result === false) { return $result; } $r = array(); if (mysql_num_rows($result)) { while ($x = mysql_fetch_array($result, MYSQL_ASSOC)) { $r[] = $x; } mysql_free_result($result); if ($this->debug) { logger('dba_mysql: ' . printable(print_r($r, true))); } } return $r; }
function q($sql) { if (!$this->db || !$this->connected) { return false; } if (!strpos($sql, ';')) { $sql .= ';'; } if (strpos($sql, '`')) { // this is a hack. quoted identifiers should be replaced everywhere in the code with dbesc_identifier(), remove this once it is $sql = str_replace('`', '"', $sql); } $this->error = ''; $result = @pg_query($this->db, $sql); if (file_exists('db-allqueries.out')) { $bt = debug_backtrace(); $trace = array(); foreach ($bt as $frame) { if (!empty($frame['file']) && @strstr($frame['file'], $_SERVER['DOCUMENT_ROOT'])) { $frame['file'] = substr($frame['file'], strlen($_SERVER['DOCUMENT_ROOT']) + 1); } $trace[] = $frame['file'] . ':' . $frame['function'] . '():' . $frame['line']; } $compact = join(', ', $trace); file_put_contents('db-allqueries.out', datetime_convert() . ": " . $sql . ' is_resource: ' . var_export(is_resource($result), true) . ', backtrace: ' . $compact . "\n\n", FILE_APPEND); } if ($result === false) { $this->error = pg_last_error($this->db); } if ($result === false || $this->error) { //logger('dba_postgres: ' . 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 ($result === true || $result === false) { return $result; } if (pg_result_status($result) == PGSQL_COMMAND_OK) { return true; } $r = array(); if (pg_num_rows($result)) { while ($x = pg_fetch_array($result, null, PGSQL_ASSOC)) { $r[] = $x; } pg_free_result($result); if ($this->debug) { logger('dba_postgres: ' . printable(print_r($r, true))); } } return $r; }
public function q($sql) { global $debug_text; if (!$this->db) { return false; } $result = @$this->db->query($sql); if ($this->debug) { $mesg = ''; if ($this->db->mysqli->errno) { $debug_text .= $this->db->mysqli->error . EOL; } if ($result === false) { $mesg = 'false'; } elseif ($result === true) { $mesg = 'true'; } else { $mesg = $result->num_rows . ' results' . EOL; } $str = 'SQL = ' . printable($sql) . EOL . 'SQL returned ' . $mesg . EOL; switch ($this->debug) { case 3: echo $str; break; default: $debug_text .= $str; break; } } if ($result === true || $result === false) { return $result; } $r = array(); if ($result->num_rows) { while ($x = $result->fetch_array(MYSQL_ASSOC)) { $r[] = $x; } $result->free_result(); } if ($this->debug == 2) { $debug_text .= printable(print_r($r, true) . EOL); } elseif ($this->debug == 3) { echo printable(print_r($r, true) . EOL); } return $r; }
function q($sql) { if (!$this->db || !$this->connected) { return false; } $this->error = ''; $select = stripos($sql, 'select') === 0 ? true : false; try { $result = $this->db->query($sql); } catch (PDOException $e) { $this->error = $e->getMessage(); if ($this->error) { db_logger('dba_mysqli: ERROR: ' . printable($sql) . "\n" . $this->error, LOGGER_NORMAL, LOG_ERR); if (file_exists('dbfail.out')) { file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . "\n" . $this->error . "\n", FILE_APPEND); } } } if (!$select) { if ($this->debug) { db_logger('dba_mysqli: DEBUG: ' . printable($sql) . ' returns ' . ($result ? 'true' : 'false'), LOGGER_NORMAL, $result ? LOG_INFO : LOG_ERR); } return $result; } if ($this->debug) { db_logger('dba_mysqli: DEBUG: ' . printable($sql) . ' returned ' . count($result) . ' results.', LOGGER_NORMAL, LOG_INFO); } $r = array(); if ($result) { foreach ($result as $x) { $r[] = $x; } if ($this->debug) { db_logger('dba_pdo: ' . printable(print_r($r, true)), LOGGER_NORMAL, LOG_INFO); } } return $r; }
function q($sql) { if (!$this->db || !$this->connected) { return false; } $this->error = ''; $result = $this->db->query($sql); if ($this->db->errno) { $this->error = $this->db->error; } if ($this->error) { db_logger('dba_mysqli: ERROR: ' . printable($sql) . "\n" . $this->error, LOGGER_NORMAL, LOG_ERR); if (file_exists('dbfail.out')) { file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . "\n" . $this->error . "\n", FILE_APPEND); } } if ($result === true || $result === false) { if ($this->debug) { db_logger('dba_mysqli: DEBUG: ' . printable($sql) . ' returns ' . ($result ? 'true' : 'false'), LOGGER_NORMAL, $result ? LOG_INFO : LOG_ERR); } return $result; } if ($this->debug) { db_logger('dba_mysqli: DEBUG: ' . printable($sql) . ' returned ' . $result->num_rows . ' results.', LOGGER_NORMAL, LOG_INFO); } $r = array(); if ($result->num_rows) { while ($x = $result->fetch_array(MYSQLI_ASSOC)) { $r[] = $x; } $result->free_result(); if ($this->debug) { db_logger('dba_mysqli: ' . printable(print_r($r, true)), LOGGER_NORMAL, LOG_INFO); } } return $r; }
public function q($sql) { if (!$this->db || !$this->connected) { return false; } if ($this->mysqli) { $result = @$this->db->query($sql); } else { $result = @mysql_query($sql, $this->db); } if ($this->debug) { $mesg = ''; if ($this->mysqli) { if ($this->db->errno) { logger('dba: ' . $this->db->error); } } elseif (mysql_errno($this->db)) { logger('dba: ' . mysql_error($this->db)); } if ($result === false) { $mesg = 'false'; } elseif ($result === true) { $mesg = 'true'; } else { if ($this->mysqli) { $mesg = $result->num_rows . ' results' . EOL; } else { $mesg = mysql_num_rows($result) . ' results' . EOL; } } $str = 'SQL = ' . printable($sql) . EOL . 'SQL returned ' . $mesg . EOL; logger('dba: ' . $str); } else { /** * If dbfail.out exists, we will write any failed calls directly to it, * regardless of any logging that may or may nor be in effect. * These usually indicate SQL syntax errors that need to be resolved. */ if ($result === false) { logger('dba: ' . printable($sql) . ' returned false.'); if (file_exists('dbfail.out')) { file_put_contents('dbfail.out', printable($sql) . ' returned false' . "\n", FILE_APPEND); } } } if ($result === true || $result === false) { return $result; } $r = array(); if ($this->mysqli) { if ($result->num_rows) { while ($x = $result->fetch_array(MYSQL_ASSOC)) { $r[] = $x; } $result->free_result(); } } else { if (mysql_num_rows($result)) { while ($x = mysql_fetch_array($result, MYSQL_ASSOC)) { $r[] = $x; } mysql_free_result($result); } } if ($this->debug) { logger('dba: ' . printable(print_r($r, true)), LOGGER_DATA); } return $r; }
public function q($sql) { global $a; if (!$this->db || !$this->connected) { return false; } $this->error = ''; $stamp1 = microtime(true); if ($this->mysqli) { $result = @$this->db->query($sql); } else { $result = @mysql_query($sql, $this->db); } $stamp2 = microtime(true); $duration = (double) ($stamp2 - $stamp1); 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"], $duration . "\t" . basename($backtrace[1]["file"]) . "\t" . $backtrace[1]["line"] . "\t" . $backtrace[2]["function"] . "\t" . substr($sql, 0, 2000) . "\n", FILE_APPEND); } } if ($this->mysqli) { if ($this->db->errno) { $this->error = $this->db->error; } } elseif (mysql_errno($this->db)) { $this->error = mysql_error($this->db); } if (strlen($this->error)) { logger('dba: ' . $this->error); } if ($this->debug) { $mesg = ''; if ($result === false) { $mesg = 'false'; } elseif ($result === true) { $mesg = 'true'; } else { if ($this->mysqli) { $mesg = $result->num_rows . ' results' . EOL; } else { $mesg = mysql_num_rows($result) . ' results' . EOL; } } $str = 'SQL = ' . printable($sql) . EOL . 'SQL returned ' . $mesg . ($this->error ? ' error: ' . $this->error : '') . EOL; logger('dba: ' . $str); } /** * If dbfail.out exists, we will write any failed calls directly to it, * regardless of any logging that may or may nor be in effect. * These usually indicate SQL syntax errors that need to be resolved. */ if ($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 ($result === true || $result === false) { return $result; } $r = array(); if ($this->mysqli) { if ($result->num_rows) { while ($x = $result->fetch_array(MYSQLI_ASSOC)) { $r[] = $x; } $result->free_result(); } } else { if (mysql_num_rows($result)) { while ($x = mysql_fetch_array($result, MYSQL_ASSOC)) { $r[] = $x; } mysql_free_result($result); } } $a->save_timestamp($stamp1, "database"); if ($this->debug) { logger('dba: ' . printable(print_r($r, true))); } return $r; }
public function q($sql) { if (!$this->db || !$this->connected) { return false; } $this->error = ''; //if (get_config("system", "db_log") != "") // @file_put_contents(get_config("system", "db_log"), datetime_convert().':'.session_id(). ' Start '.$sql."\n", FILE_APPEND); if ($this->mysqli) { $result = @$this->db->query($sql); } else { $result = @mysql_query($sql, $this->db); } //if (get_config("system", "db_log") != "") // @file_put_contents(get_config("system", "db_log"), datetime_convert().':'.session_id(). ' Stop '."\n", FILE_APPEND); if ($this->mysqli) { if ($this->db->errno) { $this->error = $this->db->error; } } elseif (mysql_errno($this->db)) { $this->error = mysql_error($this->db); } if (strlen($this->error)) { logger('dba: ' . $this->error); } if ($this->debug) { $mesg = ''; if ($result === false) { $mesg = 'false'; } elseif ($result === true) { $mesg = 'true'; } else { if ($this->mysqli) { $mesg = $result->num_rows . ' results' . EOL; } else { $mesg = mysql_num_rows($result) . ' results' . EOL; } } $str = 'SQL = ' . printable($sql) . EOL . 'SQL returned ' . $mesg . ($this->error ? ' error: ' . $this->error : '') . EOL; logger('dba: ' . $str); } /** * If dbfail.out exists, we will write any failed calls directly to it, * regardless of any logging that may or may nor be in effect. * These usually indicate SQL syntax errors that need to be resolved. */ if ($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 ($result === true || $result === false) { return $result; } $r = array(); if ($this->mysqli) { if ($result->num_rows) { while ($x = $result->fetch_array(MYSQLI_ASSOC)) { $r[] = $x; } $result->free_result(); } } else { if (mysql_num_rows($result)) { while ($x = mysql_fetch_array($result, MYSQL_ASSOC)) { $r[] = $x; } mysql_free_result($result); } } if ($this->debug) { logger('dba: ' . printable(print_r($r, true))); } return $r; }