From 27738491fc11d0b9ce5670b2f6a7957fc421ee4b Mon Sep 17 00:00:00 2001 From: Rogerio Prado de Jesus Date: Sat, 19 May 2012 13:45:44 -0300 Subject: Fix a issue with CI_DB_pdo_result::num_rows() In case of SELECT queries PDOStatement::rowCount doesn't work as expected. This commit makes it returns the expected value. --- system/database/drivers/pdo/pdo_result.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php index 7f3058ff0..c05fbc908 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -34,7 +34,18 @@ class CI_DB_pdo_result extends CI_DB_result { */ function num_rows() { - return $this->result_id->rowCount(); + if (is_numeric(stripos($this->result_id->queryString, 'SELECT'))) + { + $dbh = $this->conn_id; + $query = $dbh->query($this->result_id->queryString); + $result = $query->fetchAll(); + unset($dbh, $query); + return count($result); + } + else + { + return $this->result_id->rowCount(); + } } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b