From 694b5b8ee6a40b57c91be3c5448bc8f5540d32d8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 18 Dec 2007 15:58:03 +0000 Subject: Added count_all_results() function to Active Record. --- system/database/drivers/mysql/mysql_driver.php | 32 ++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/mysql') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 2e1f30f21..69a238d94 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -30,6 +30,13 @@ */ class CI_DB_mysql_driver extends CI_DB { + /** + * The syntax to count rows is slightly different across different + * database engines, so this string appears in each driver and is + * used for the count_all() and count_all_results() functions. + */ + var $count_string = "SELECT COUNT(*) AS numrows "; + /** * Whether to use the MySQL "delete hack" which allows the number * of affected rows to be shown. Uses a preg_replace when enabled, @@ -222,7 +229,17 @@ class CI_DB_mysql_driver extends CI_DB { */ function escape_str($str) { - if (function_exists('mysql_real_escape_string')) + if (is_array($str)) + { + foreach($str as $key => $val) + { + $str[$key] = $this->escape_str($val); + } + + return $str; + } + + if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id)) { return mysql_real_escape_string($str, $this->conn_id); } @@ -279,7 +296,7 @@ class CI_DB_mysql_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + $query = $this->query($this->count_string . "FROM `".$this->dbprefix.$table."`"); if ($query->num_rows() == 0) return '0'; @@ -298,9 +315,16 @@ class CI_DB_mysql_driver extends CI_DB { * @access private * @return string */ - function _list_tables() + function _list_tables($prefix_limit = FALSE) { - return "SHOW TABLES FROM `".$this->database."`"; + $sql = "SHOW TABLES FROM `".$this->database."`"; + + if ($prefix_limit !== FALSE AND $this->_stdprefix != '') + { + $sql .= " LIKE '".$this->_stdprefix."%'"; + } + + return $sql; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b