- public function q($sql, $onlyquery = false) {
- $a = get_app();
-
- if (!$this->db || !$this->connected) {
- return false;
- }
-
- $this->error = '';
-
- $connstr = ($this->connected() ? "Connected" : "Disonnected");
-
- $stamp1 = microtime(true);
-
- $orig_sql = $sql;
-
- if (x($a->config,'system') && x($a->config['system'], 'db_callstack')) {
- $sql = "/*".$a->callstack()." */ ".$sql;
- }
-
- $columns = 0;
-
- switch ($this->driver) {
- case 'pdo':
- $result = @$this->db->query($sql);
- // Is used to separate between queries that returning data - or not
- if (!is_bool($result)) {
- $columns = $result->columnCount();
- }
- break;
- case 'mysqli':
- $result = @$this->db->query($sql);
- break;
- case 'mysql':
- $result = @mysql_query($sql,$this->db);
- break;
- }
- $stamp2 = microtime(true);
- $duration = (float)($stamp2 - $stamp1);
-
- $a->save_timestamp($stamp1, "database");
-
- if (strtolower(substr($orig_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);
- $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);
- }
- }
-
- switch ($this->driver) {