Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -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 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 7 | * NOTICE OF LICENSE |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 20 | * @author EllisLab Dev Team |
| 21 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) |
| 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
| 28 | // -------------------------------------------------------------------- |
| 29 | |
| 30 | /** |
| 31 | * MySQL Result Class |
| 32 | * |
| 33 | * This class extends the parent result class: CI_DB_result |
| 34 | * |
| 35 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 36 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/database/ |
| 38 | */ |
| 39 | class CI_DB_mysql_result extends CI_DB_result { |
| 40 | |
| 41 | /** |
| 42 | * Number of rows in the result set |
| 43 | * |
| 44 | * @access public |
| 45 | * @return integer |
| 46 | */ |
| 47 | function num_rows() |
| 48 | { |
| 49 | return @mysql_num_rows($this->result_id); |
| 50 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 51 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 52 | // -------------------------------------------------------------------- |
| 53 | |
| 54 | /** |
| 55 | * Number of fields in the result set |
| 56 | * |
| 57 | * @access public |
| 58 | * @return integer |
| 59 | */ |
| 60 | function num_fields() |
| 61 | { |
| 62 | return @mysql_num_fields($this->result_id); |
| 63 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 64 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 65 | // -------------------------------------------------------------------- |
| 66 | |
| 67 | /** |
| 68 | * Fetch Field Names |
| 69 | * |
| 70 | * Generates an array of column names |
| 71 | * |
| 72 | * @access public |
| 73 | * @return array |
| 74 | */ |
| 75 | function list_fields() |
| 76 | { |
| 77 | $field_names = array(); |
| 78 | while ($field = mysql_fetch_field($this->result_id)) |
| 79 | { |
| 80 | $field_names[] = $field->name; |
| 81 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 82 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 83 | return $field_names; |
| 84 | } |
| 85 | |
| 86 | // -------------------------------------------------------------------- |
| 87 | |
| 88 | /** |
| 89 | * Field data |
| 90 | * |
| 91 | * Generates an array of objects containing field meta-data |
| 92 | * |
| 93 | * @access public |
| 94 | * @return array |
| 95 | */ |
| 96 | function field_data() |
| 97 | { |
| 98 | $retval = array(); |
danmontgomery | fc75645 | 2011-08-21 15:31:22 -0400 | [diff] [blame] | 99 | while ($field = mysql_fetch_object($this->result_id)) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 100 | { |
Phil Sturgeon | 4c90723 | 2011-08-28 17:11:03 +0100 | [diff] [blame] | 101 | preg_match('/([a-zA-Z]+)(\((\d+)\))?/i', $field->Type, $matches); |
danmontgomery | fc75645 | 2011-08-21 15:31:22 -0400 | [diff] [blame] | 102 | |
| 103 | $type = $matches[1]; |
Phil Sturgeon | 4c90723 | 2011-08-28 17:11:03 +0100 | [diff] [blame] | 104 | $length = isset($matches[3]) ? (int) $matches[3] : NULL; |
danmontgomery | fc75645 | 2011-08-21 15:31:22 -0400 | [diff] [blame] | 105 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 106 | $F = new stdClass(); |
danmontgomery | fc75645 | 2011-08-21 15:31:22 -0400 | [diff] [blame] | 107 | $F->name = $field->Field; |
| 108 | $F->type = $type; |
| 109 | $F->default = $field->Default; |
| 110 | $F->max_length = $length; |
| 111 | $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 ); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 112 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 113 | $retval[] = $F; |
| 114 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 115 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 116 | return $retval; |
| 117 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 118 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 119 | // -------------------------------------------------------------------- |
| 120 | |
| 121 | /** |
| 122 | * Free the result |
| 123 | * |
| 124 | * @return null |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 125 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 126 | function free_result() |
| 127 | { |
| 128 | if (is_resource($this->result_id)) |
| 129 | { |
| 130 | mysql_free_result($this->result_id); |
| 131 | $this->result_id = FALSE; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | // -------------------------------------------------------------------- |
| 136 | |
| 137 | /** |
| 138 | * Data Seek |
| 139 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 140 | * Moves the internal pointer to the desired offset. We call |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 141 | * this internally before fetching results to make sure the |
| 142 | * result set starts at zero |
| 143 | * |
| 144 | * @access private |
| 145 | * @return array |
| 146 | */ |
| 147 | function _data_seek($n = 0) |
| 148 | { |
| 149 | return mysql_data_seek($this->result_id, $n); |
| 150 | } |
| 151 | |
| 152 | // -------------------------------------------------------------------- |
| 153 | |
| 154 | /** |
| 155 | * Result - associative array |
| 156 | * |
| 157 | * Returns the result set as an array |
| 158 | * |
| 159 | * @access private |
| 160 | * @return array |
| 161 | */ |
| 162 | function _fetch_assoc() |
| 163 | { |
| 164 | return mysql_fetch_assoc($this->result_id); |
| 165 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 166 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 167 | // -------------------------------------------------------------------- |
| 168 | |
| 169 | /** |
| 170 | * Result - object |
| 171 | * |
| 172 | * Returns the result set as an object |
| 173 | * |
| 174 | * @access private |
| 175 | * @return object |
| 176 | */ |
| 177 | function _fetch_object() |
| 178 | { |
| 179 | return mysql_fetch_object($this->result_id); |
| 180 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 181 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | |
| 185 | /* End of file mysql_result.php */ |
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 186 | /* Location: ./system/database/drivers/mysql/mysql_result.php */ |