diff options
author | Eric Roberts <eric@cryode.com> | 2012-12-12 14:02:11 +0100 |
---|---|---|
committer | Eric Roberts <eric@cryode.com> | 2012-12-12 14:02:11 +0100 |
commit | b9e35f21e1c70b6aa67c47e9244ed83195abc00a (patch) | |
tree | 64f82db362deeac48cc20d1d1afd80651f36f5a5 /system/database/drivers/mysql/mysql_result.php | |
parent | 0b05705c52c3bca7f9b3aee657c888e8ad1ff422 (diff) | |
parent | 545a7c86701875e1412bcde316e9bcc76d9a23a0 (diff) |
Merge branch 'refs/heads/develop' into feature/form_error_msgs
Conflicts:
system/language/english/form_validation_lang.php
user_guide_src/source/libraries/form_validation.rst
Signed-off-by: Eric Roberts <eric@cryode.com>
Diffstat (limited to 'system/database/drivers/mysql/mysql_result.php')
-rw-r--r-- | system/database/drivers/mysql/mysql_result.php | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 14d6d072a..293980e97 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -1,4 +1,4 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php /** * CodeIgniter * @@ -24,6 +24,7 @@ * @since Version 1.0 * @filesource */ +defined('BASEPATH') OR exit('No direct script access allowed'); /** * MySQL Result Class @@ -33,17 +34,35 @@ * @category Database * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/database/ + * @since 1.0 */ class CI_DB_mysql_result extends CI_DB_result { /** + * Class constructor + * + * @param object &$driver_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 * * @return int */ public function num_rows() { - return @mysql_num_rows($this->result_id); + return $this->num_rows; } // -------------------------------------------------------------------- @@ -96,8 +115,7 @@ class CI_DB_mysql_result extends CI_DB_result { $retval[$i]->name = mysql_field_name($this->result_id, $i); $retval[$i]->type = mysql_field_type($this->result_id, $i); $retval[$i]->max_length = mysql_field_len($this->result_id, $i); - $retval[$i]->primary_key = (strpos(mysql_field_flags($this->result_id, $i), 'primary_key') === FALSE) ? 0 : 1; - $retval[$i]->default = ''; + $retval[$i]->primary_key = (int) (strpos(mysql_field_flags($this->result_id, $i), 'primary_key') !== FALSE); } return $retval; @@ -126,13 +144,16 @@ class CI_DB_mysql_result extends CI_DB_result { * * Moves the internal pointer to the desired offset. We call * this internally before fetching results to make sure the - * result set starts at zero + * result set starts at zero. * + * @param int $n * @return bool */ - protected function _data_seek($n = 0) + public 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; } // -------------------------------------------------------------------- @@ -156,11 +177,12 @@ class CI_DB_mysql_result extends CI_DB_result { * * Returns the result set as an object * + * @param string $class_name * @return object */ - protected function _fetch_object() + protected function _fetch_object($class_name = 'stdClass') { - return mysql_fetch_object($this->result_id); + return mysql_fetch_object($this->result_id, $class_name); } } |