diff --git a/src/Database/Mysql/Mysql.php b/src/Database/Mysql/Mysql.php index d80250d..421c274 100644 --- a/src/Database/Mysql/Mysql.php +++ b/src/Database/Mysql/Mysql.php @@ -61,7 +61,7 @@ public function query($statement, $fetchAll = true, $fetchMode = 'obj') $this->sqlQuery = $this->pdo ->query($statement); - if (isset($this->sqlQuery)) { + if (isset($this->sqlQuery) && !is_bool($this->sqlQuery)) { $this->rowCount = $this->sqlQuery ->rowCount(); @@ -97,7 +97,7 @@ public function prepare($statement, array $attributes, $fetchAll = true, $fetchM $executeResponse = $this->sqlQuery ->execute($attributes); - if (isset($this->sqlQuery)) { + if (isset($this->sqlQuery) && !is_bool($this->sqlQuery)) { $this->rowCount = $this->sqlQuery ->rowCount(); diff --git a/src/Query/Query.php b/src/Query/Query.php index 498805b..8c390eb 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -103,7 +103,7 @@ public function get(array $fetchAttributes = null, array $executeAttributes = nu public function exec() { try { - return $this->query($this->sqlQuery, $this->sqlAttributes, false); + return $this->query($this->sqlQuery, empty($this->sqlAttributes) ? ['all'] : $this->sqlAttributes, false); } catch (Exception $e) { return [$e->getMessage()]; } @@ -135,6 +135,17 @@ public function orderBy($orders) return $this; } + public function groupBy($groups) + { + foreach ($groups as $value) { + $queryGroups[] = $value; + } + + $this->sqlQuery .=' GROUP BY '.implode(',', $queryGroups); + + return $this; + } + public function where($conditions, $or = false) { foreach ($conditions as $key => $value) { @@ -145,7 +156,7 @@ public function where($conditions, $or = false) } } - if (isset($or)) { + if (isset($or) && $or !== false) { $this->sqlQuery .= ' WHERE '.implode(' OR ', $fieldConditions); return $this; @@ -198,4 +209,9 @@ public function close() { return $this->pdo->disconnect(); } + + public function error() + { + return $this->pdo->get(); + } }