public function query($query, $all = true, $array = false)
{
$this->reset();
if (is_array($all)) {
$x = explode('?', $query);
$q = '';
foreach ($x as $k => $v) {
if (!empty($v)) {
$q .= $v . (isset($all[$k]) ? $this->escape($all[$k]) : '');
}
}
$query = $q;
}
$this->query = preg_replace('/\\s\\s+|\\t\\t+/', ' ', trim($query));
$str = stristr($this->query, 'SELECT');
$cache = false;
if (!is_null($this->cache)) {
$cache = $this->cache->getCache($this->query, $array);
}
if (!$cache && $str) {
$sql = $this->pdo->query($this->query);
if ($sql) {
$this->numRows = $sql->rowCount();
if ($this->numRows > 0) {
if ($all) {
$q = [];
while ($result = $array == false ? $sql->fetchAll(PDO::FETCH_OBJ) : $sql->fetchAll(PDO::FETCH_ASSOC)) {
$q[] = $result;
}
$this->result = $q[0];
} else {
$q = $array == false ? $sql->fetch(PDO::FETCH_OBJ) : $sql->fetch(PDO::FETCH_ASSOC);
$this->result = $q;
}
}
if (!is_null($this->cache)) {
$this->cache->setCache($this->query, $this->result);
}
$this->cache = null;
} else {
$this->cache = null;
$this->error = $this->pdo->errorInfo();
$this->error = $this->error[2];
return $this->error();
}
} elseif (!$cache && !$str || $cache && !$str) {
$this->cache = null;
$this->result = $this->pdo->query($this->query);
if (!$this->result) {
$this->error = $this->pdo->errorInfo();
$this->error = $this->error[2];
return $this->error();
}
} else {
$this->cache = null;
$this->result = $cache;
}
$this->queryCount++;
return $this->result;
}