/** * @param string $sql * @param bool $noexcept * @return bool|stdClass * @throws AException */ public function query($sql, $noexcept = false) { //echo $this->database_name; $time_start = microtime(true); $sql = $this->_sql_prepare($sql); $resource = pg_query($this->connection, $sql); $this->result = $resource; $time_exec = microtime(true) - $time_start; // to avoid debug class init while setting was not yet loaded if ($this->registry->get('config')) { if ($this->registry->get('config')->has('config_debug')) { $backtrace = debug_backtrace(); ADebug::set_query($sql, $time_exec, $backtrace[2]); } } if ($resource) { if (is_resource($resource)) { //get last id for inserts if (is_int(strpos($sql, 'INSERT INTO'))) { $insert_query = pg_query("SELECT lastval();"); $insert_row = pg_fetch_row($insert_query); $this->last_id = $insert_row[0]; } $i = 0; $data = array(); while ($result = pg_fetch_assoc($resource)) { $data[$i] = $result; $i++; } pg_free_result($resource); $query = new stdClass(); $query->row = isset($data[0]) ? $data[0] : array(); $query->rows = $data; $query->num_rows = $i; unset($data); return $query; } else { return TRUE; } } else { if ($noexcept) { $this->error = 'AbanteCart Error: ' . pg_result_error($resource) . '<br />' . $sql; return FALSE; } else { throw new AException(AC_ERR_MYSQL, 'Error: ' . pg_result_error($resource) . '<br />' . $sql); } } }
public function query($sql, $noexcept = false, $params = array()) { if (!$noexcept) { $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); } $this->statement = $this->connection->prepare($sql); $result = false; $time_start = microtime(true); try { if ($this->statement && $this->statement->execute($params)) { $data = array(); if ($this->statement->columnCount()) { while ($row = $this->statement->fetch(PDO::FETCH_ASSOC)) { $data[] = $row; } $result = new stdClass(); $result->row = isset($data[0]) ? $data[0] : array(); $result->rows = $data; $result->num_rows = $this->statement->rowCount(); } } } catch (PDOException $e) { $this->error = 'SQL Error: ' . $e->getMessage() . '<br />Error No: ' . $e->getCode() . '<br />SQL:' . $sql; if ($noexcept) { return false; } else { throw new AException(AC_ERR_MYSQL, $this->error); } } $time_exec = microtime(true) - $time_start; // to avoid debug class init while setting was not yet loaded if ($this->registry->get('config')) { if ($this->registry->get('config')->has('config_debug')) { $backtrace = debug_backtrace(); ADebug::set_query($sql, $time_exec, $backtrace[2]); } } if ($result) { return $result; } else { $result = new stdClass(); $result->row = array(); $result->rows = array(); $result->num_rows = 0; return $result; } }
/** * @param string $sql * @param bool $noexcept * @return bool|stdClass * @throws AException */ public function query($sql, $noexcept = false) { //echo $this->database_name; $time_start = microtime(true); $resource = mysql_query($sql, $this->connection); $time_exec = microtime(true) - $time_start; // to avoid debug class init while setting was not yet loaded if ($this->registry->get('config')) { if ($this->registry->get('config')->has('config_debug')) { $backtrace = debug_backtrace(); ADebug::set_query($sql, $time_exec, $backtrace[2]); } } if ($resource) { if (is_resource($resource)) { $i = 0; $data = array(); while ($result = mysql_fetch_assoc($resource)) { $data[$i] = $result; $i++; } mysql_free_result($resource); $query = new stdClass(); $query->row = isset($data[0]) ? $data[0] : array(); $query->rows = $data; $query->num_rows = $i; unset($data); return $query; } else { return TRUE; } } else { if ($noexcept) { $this->error = 'AbanteCart Error: ' . mysql_error($this->connection) . '<br />Error No: ' . mysql_errno($this->connection) . '<br />' . $sql; return FALSE; } else { throw new AException(AC_ERR_MYSQL, 'Error: ' . mysql_error($this->connection) . '<br />Error No: ' . mysql_errno($this->connection) . '<br />' . $sql); } } }
/** * @param string $sql * @param bool $noexcept * @return bool|stdClass * @throws AException */ public function query($sql, $noexcept = false) { //echo $this->database_name; $time_start = microtime(true); $result = $this->connection->query($sql); $time_exec = microtime(true) - $time_start; // to avoid debug class init while setting was not yet loaded if ($this->registry->get('config')) { if ($this->registry->get('config')->has('config_debug')) { $backtrace = debug_backtrace(); ADebug::set_query($sql, $time_exec, $backtrace[2]); } } if ($result) { if (!is_bool($result)) { $i = 0; $data = array(); while ($row = $result->fetch_object()) { $data[$i] = (array) $row; $i++; } $query = new stdClass(); $query->row = isset($data[0]) ? $data[0] : array(); $query->rows = $data; $query->num_rows = (int) $result->num_rows; unset($data); return $query; } else { return TRUE; } } else { if ($noexcept) { $this->error = 'AbanteCart Error: ' . $result->error . '<br />' . $sql; return FALSE; } else { throw new AException(AC_ERR_MYSQL, 'Error: ' . $result->error . '<br />' . $sql); } } }