Skip to content

Commit 31380e8

Browse files
committed
Alter CI_DB_pdo_result::num_rows()
1 parent a8126b1 commit 31380e8

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

system/database/drivers/pdo/pdo_result.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,27 @@
2626
*/
2727
class CI_DB_pdo_result extends CI_DB_result {
2828

29+
public $num_rows;
30+
2931
/**
3032
* Number of rows in the result set
3133
*
32-
* @access public
33-
* @return integer
34+
* @return int
3435
*/
35-
function num_rows()
36+
public function num_rows()
3637
{
37-
if (is_numeric(stripos($this->result_id->queryString, 'SELECT')))
38+
if (is_int($this->num_rows))
3839
{
39-
$dbh = $this->conn_id;
40-
$query = $dbh->query($this->result_id->queryString);
41-
$result = $query->fetchAll();
42-
unset($dbh, $query);
43-
return count($result);
40+
return $this->num_rows;
4441
}
45-
else
42+
elseif (($this->num_rows = $this->result_id->rowCount()) > 0)
4643
{
47-
return $this->result_id->rowCount();
44+
return $this->num_rows;
4845
}
46+
47+
$this->num_rows = count($this->result_id->fetchAll());
48+
$this->result_id->execute();
49+
return $this->num_rows;
4950
}
5051

5152
// --------------------------------------------------------------------

0 commit comments

Comments
 (0)