Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author ExpressionEngine Dev Team |
Greg Aker | 0711dc8 | 2011-01-05 10:49:40 -0600 | [diff] [blame] | 9 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html |
| 11 | * @link http://codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // -------------------------------------------------------------------- |
| 17 | |
| 18 | /** |
| 19 | * MySQL Result Class |
| 20 | * |
| 21 | * This class extends the parent result class: CI_DB_result |
| 22 | * |
| 23 | * @category Database |
| 24 | * @author ExpressionEngine Dev Team |
| 25 | * @link http://codeigniter.com/user_guide/database/ |
| 26 | */ |
| 27 | class CI_DB_mysql_result extends CI_DB_result { |
| 28 | |
| 29 | /** |
| 30 | * Number of rows in the result set |
| 31 | * |
| 32 | * @access public |
| 33 | * @return integer |
| 34 | */ |
| 35 | function num_rows() |
| 36 | { |
| 37 | return @mysql_num_rows($this->result_id); |
| 38 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | // -------------------------------------------------------------------- |
| 41 | |
| 42 | /** |
| 43 | * Number of fields in the result set |
| 44 | * |
| 45 | * @access public |
| 46 | * @return integer |
| 47 | */ |
| 48 | function num_fields() |
| 49 | { |
| 50 | return @mysql_num_fields($this->result_id); |
| 51 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 52 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 53 | // -------------------------------------------------------------------- |
| 54 | |
| 55 | /** |
| 56 | * Fetch Field Names |
| 57 | * |
| 58 | * Generates an array of column names |
| 59 | * |
| 60 | * @access public |
| 61 | * @return array |
| 62 | */ |
| 63 | function list_fields() |
| 64 | { |
| 65 | $field_names = array(); |
| 66 | while ($field = mysql_fetch_field($this->result_id)) |
| 67 | { |
| 68 | $field_names[] = $field->name; |
| 69 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 70 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 71 | return $field_names; |
| 72 | } |
| 73 | |
| 74 | // -------------------------------------------------------------------- |
| 75 | |
| 76 | /** |
| 77 | * Field data |
| 78 | * |
| 79 | * Generates an array of objects containing field meta-data |
| 80 | * |
| 81 | * @access public |
| 82 | * @return array |
| 83 | */ |
| 84 | function field_data() |
| 85 | { |
| 86 | $retval = array(); |
danmontgomery | ad4681f | 2011-08-21 15:31:22 -0400 | [diff] [blame] | 87 | while ($field = mysql_fetch_object($this->result_id)) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 88 | { |
Phil Sturgeon | 659baa9 | 2011-10-27 13:24:53 +0100 | [diff] [blame] | 89 | preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches); |
danmontgomery | ad4681f | 2011-08-21 15:31:22 -0400 | [diff] [blame] | 90 | |
Phil Sturgeon | 659baa9 | 2011-10-27 13:24:53 +0100 | [diff] [blame] | 91 | $type = (array_key_exists(1, $matches)) ? $matches[1] : NULL; |
| 92 | $length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; |
danmontgomery | ad4681f | 2011-08-21 15:31:22 -0400 | [diff] [blame] | 93 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 94 | $F = new stdClass(); |
danmontgomery | ad4681f | 2011-08-21 15:31:22 -0400 | [diff] [blame] | 95 | $F->name = $field->Field; |
| 96 | $F->type = $type; |
| 97 | $F->default = $field->Default; |
| 98 | $F->max_length = $length; |
| 99 | $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 ); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 100 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 101 | $retval[] = $F; |
| 102 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 103 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 104 | return $retval; |
| 105 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 106 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 107 | // -------------------------------------------------------------------- |
| 108 | |
| 109 | /** |
| 110 | * Free the result |
| 111 | * |
| 112 | * @return null |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 113 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 114 | function free_result() |
| 115 | { |
| 116 | if (is_resource($this->result_id)) |
| 117 | { |
| 118 | mysql_free_result($this->result_id); |
| 119 | $this->result_id = FALSE; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // -------------------------------------------------------------------- |
| 124 | |
| 125 | /** |
| 126 | * Data Seek |
| 127 | * |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 128 | * Moves the internal pointer to the desired offset. We call |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 129 | * this internally before fetching results to make sure the |
| 130 | * result set starts at zero |
| 131 | * |
| 132 | * @access private |
| 133 | * @return array |
| 134 | */ |
| 135 | function _data_seek($n = 0) |
| 136 | { |
| 137 | return mysql_data_seek($this->result_id, $n); |
| 138 | } |
| 139 | |
| 140 | // -------------------------------------------------------------------- |
| 141 | |
| 142 | /** |
| 143 | * Result - associative array |
| 144 | * |
| 145 | * Returns the result set as an array |
| 146 | * |
| 147 | * @access private |
| 148 | * @return array |
| 149 | */ |
| 150 | function _fetch_assoc() |
| 151 | { |
| 152 | return mysql_fetch_assoc($this->result_id); |
| 153 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 154 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 155 | // -------------------------------------------------------------------- |
| 156 | |
| 157 | /** |
| 158 | * Result - object |
| 159 | * |
| 160 | * Returns the result set as an object |
| 161 | * |
| 162 | * @access private |
| 163 | * @return object |
| 164 | */ |
| 165 | function _fetch_object() |
| 166 | { |
| 167 | return mysql_fetch_object($this->result_id); |
| 168 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 169 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | |
| 173 | /* End of file mysql_result.php */ |
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 174 | /* Location: ./system/database/drivers/mysql/mysql_result.php */ |