diff --git a/system/MagiQL/Manipulation/Select.php b/system/MagiQL/Manipulation/Select.php index 64c704c..c41193f 100644 --- a/system/MagiQL/Manipulation/Select.php +++ b/system/MagiQL/Manipulation/Select.php @@ -381,14 +381,14 @@ class Select extends AbstractBaseQuery /** * @param int $start - * @param $count + * @param int $count * * @return $this */ - public function limit($start, $count = 0) + public function limit($start, $count = null) { - $this->limitStart = $start; - $this->limitCount = $count; + $this->limitStart = $count === null ? 0 : $start; + $this->limitCount = $count === null ? $start :$count; return $this; } diff --git a/system/database/databases/mpdo.php b/system/database/databases/mpdo.php index ccc8b20..77bd3e9 100644 --- a/system/database/databases/mpdo.php +++ b/system/database/databases/mpdo.php @@ -144,7 +144,7 @@ final class mPDO implements Databases { // Bind parameters if there are any if (!empty($params)) { foreach ($params as $placeholder => &$param) { - $stmt->bindParam($placeholder, $param); + $stmt->bindParam($placeholder,$param, $this->getParamType($param)); } } @@ -153,7 +153,7 @@ final class mPDO implements Databases { if ($stmt->columnCount()) { $data = new \Phacil\Framework\Databases\Object\Result(); $data->setNumRows($stmt->rowCount()); - $data->setRows($stmt->fetchAll()); + $data->setRows($stmt->fetchAll(\PDO::FETCH_ASSOC)); //$data->setRow(isset($data->rows[0]) ? $data->rows[0] : null); $stmt->closeCursor(); @@ -168,4 +168,34 @@ final class mPDO implements Databases { throw new \Phacil\Framework\Exception($exception->getMessage()); } } + + /** + * + * @param mixed $param + * @return int + */ + private function getParamType(&$param) { + $paramType = gettype($param); + + switch ($paramType) { + case 'boolean': + $paramType = \PDO::PARAM_BOOL; + break; + case 'integer': + $paramType = \PDO::PARAM_INT; + break; + case 'double': + case 'float': + $paramType = \PDO::PARAM_STR; + break; + case 'NULL': + $paramType = \PDO::PARAM_NULL; + break; + default: + $paramType = \PDO::PARAM_STR; + break; + } + + return $paramType; + } } \ No newline at end of file diff --git a/system/database/databases/mysql_pdo.php b/system/database/databases/mysql_pdo.php index 4769020..78ccdee 100644 --- a/system/database/databases/mysql_pdo.php +++ b/system/database/databases/mysql_pdo.php @@ -99,7 +99,7 @@ class MYSQL_PDO implements Databases $sth->execute(); //$sth= $this->dbh->query($sql); $this->affectedRows = $sth->rowCount(); - $data->rows = $sth ? $sth->fetchAll() : array(); + $data->rows = $sth ? $sth->fetchAll(\PDO::FETCH_ASSOC) : array(); $data->row = isset($data->rows[0]) ? $data->rows[0] : null; $data->num_rows = $this->affectedRows; return $data; @@ -184,7 +184,7 @@ class MYSQL_PDO implements Databases // Bind parameters if there are any if (!empty($params)) { foreach ($params as $placeholder => &$param) { - $stmt->bindParam($placeholder, $param); + $stmt->bindParam($placeholder, $param, $this->getParamType($param)); } } @@ -193,7 +193,7 @@ class MYSQL_PDO implements Databases if ($stmt->columnCount()) { $data = new \Phacil\Framework\Databases\Object\Result(); $data->setNumRows($stmt->rowCount()); - $data->setRows($stmt->fetchAll()); + $data->setRows($stmt->fetchAll(\PDO::FETCH_ASSOC)); //$data->setRow(isset($data->rows[0]) ? $data->rows[0] : null); $stmt->closeCursor(); @@ -209,4 +209,35 @@ class MYSQL_PDO implements Databases throw new \Phacil\Framework\Exception($exception->getMessage()); } } + + /** + * + * @param mixed $param + * @return int + */ + private function getParamType(&$param) + { + $paramType = gettype($param); + + switch ($paramType) { + case 'boolean': + $paramType = \PDO::PARAM_BOOL; + break; + case 'integer': + $paramType = \PDO::PARAM_INT; + break; + case 'double': + case 'float': + $paramType = \PDO::PARAM_STR; + break; + case 'NULL': + $paramType = \PDO::PARAM_NULL; + break; + default: + $paramType = \PDO::PARAM_STR; + break; + } + + return $paramType; + } } \ No newline at end of file