summaryrefslogtreecommitdiffstats
path: root/system/database
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2012-05-20 13:34:46 +0200
committerPhil Sturgeon <email@philsturgeon.co.uk>2012-05-20 13:34:46 +0200
commita3ce0ec96f98e1bcd1c5a0bc088d13f3178c01c6 (patch)
tree9fa2ee9417387f5cf4bf0f108dcce25f69f0f8c2 /system/database
parentfbd31c8d98bd7e5eac5c8e8c2f102b05350db93e (diff)
parent27738491fc11d0b9ce5670b2f6a7957fc421ee4b (diff)
Merge pull request #1331 from rogeriopradoj/patch-1
Workaround for PDO Driver in 2.1-stable: num_rows doesn't work for SELECT queries
Diffstat (limited to 'system/database')
-rw-r--r--system/database/drivers/pdo/pdo_driver.php13
-rw-r--r--system/database/drivers/pdo/pdo_result.php13
2 files changed, 23 insertions, 3 deletions
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index c38b79c5a..952016848 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -189,11 +189,20 @@ class CI_DB_pdo_driver extends CI_DB {
function _execute($sql)
{
$sql = $this->_prep_query($sql);
- $result_id = $this->conn_id->query($sql);
+ $result_id = $this->conn_id->prepare($sql);
+ $result_id->execute();
if (is_object($result_id))
{
- $this->affect_rows = $result_id->rowCount();
+ if (is_numeric(stripos($sql, 'SELECT')))
+ {
+ $this->affect_rows = count($result_id->fetchAll());
+ $result_id->execute();
+ }
+ else
+ {
+ $this->affect_rows = $result_id->rowCount();
+ }
}
else
{
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();
+ }
}
// --------------------------------------------------------------------