From 35c7adc7f3d3058a29b177dcaa888c67dd174613 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Jul 2012 18:06:32 +0300 Subject: Apparently mysql_data_seek() causes problems even when we suppress and ignore it --- system/database/drivers/mysql/mysql_result.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'system/database/drivers') diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index b507f7960..a75cfad1f 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -37,6 +37,23 @@ */ class CI_DB_mysql_result extends CI_DB_result { + /** + * Constructor + * + * @param object + * @return void + */ + public function __construct(&$driver_object) + { + parent::__construct($driver_object); + + // Required, due to mysql_data_seek() causing nightmares + // with empty result sets + $this->num_rows = @mysql_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + /** * Number of rows in the result set * @@ -44,9 +61,7 @@ class CI_DB_mysql_result extends CI_DB_result { */ public function num_rows() { - return is_int($this->num_rows) - ? $this->num_rows - : $this->num_rows = @mysql_num_rows($this->result_id); + return $this->num_rows; } // -------------------------------------------------------------------- @@ -135,7 +150,9 @@ class CI_DB_mysql_result extends CI_DB_result { */ protected function _data_seek($n = 0) { - return @mysql_data_seek($this->result_id, $n); + return $this->num_rows + ? @mysql_data_seek($this->result_id, $n) + : FALSE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 9e3a83a65668cc26b685f0b35a4428809435f7c9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Jul 2012 21:57:41 +0300 Subject: Fix PDO version() --- system/database/drivers/pdo/pdo_driver.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'system/database/drivers') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 3ef376ca5..38a9fec80 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -250,9 +250,20 @@ class CI_DB_pdo_driver extends CI_DB { */ public function version() { - return isset($this->data_cache['version']) - ? $this->data_cache['version'] - : $this->data_cache['version'] = $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION); + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + // Not all subdrivers support the getAttribute() method + try + { + return $this->data_cache['version'] = $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION); + } + catch (PDOException $e) + { + return parent::version(); + } } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b