Phil Sturgeon | 0199f68 | 2011-11-22 14:57:21 +0000 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 5.1.6 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. |
| 9 | * @license http://codeigniter.com/user_guide/license.html |
| 10 | * @author EllisLab Dev Team |
| 11 | * @link http://codeigniter.com |
| 12 | * @since Version 2.1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * PDO Result Class |
| 20 | * |
| 21 | * This class extends the parent result class: CI_DB_result |
| 22 | * |
| 23 | * @category Database |
| 24 | * @author EllisLab Dev Team |
| 25 | * @link http://codeigniter.com/user_guide/database/ |
| 26 | */ |
| 27 | class CI_DB_pdo_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 | { |
Rogerio Prado de Jesus | 2773849 | 2012-05-19 13:45:44 -0300 | [diff] [blame^] | 37 | if (is_numeric(stripos($this->result_id->queryString, 'SELECT'))) |
| 38 | { |
| 39 | $dbh = $this->conn_id; |
| 40 | $query = $dbh->query($this->result_id->queryString); |
| 41 | $result = $query->fetchAll(); |
| 42 | unset($dbh, $query); |
| 43 | return count($result); |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | return $this->result_id->rowCount(); |
| 48 | } |
Phil Sturgeon | 0199f68 | 2011-11-22 14:57:21 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | // -------------------------------------------------------------------- |
| 52 | |
| 53 | /** |
| 54 | * Number of fields in the result set |
| 55 | * |
| 56 | * @access public |
| 57 | * @return integer |
| 58 | */ |
| 59 | function num_fields() |
| 60 | { |
| 61 | return $this->result_id->columnCount(); |
| 62 | } |
| 63 | |
| 64 | // -------------------------------------------------------------------- |
| 65 | |
| 66 | /** |
| 67 | * Fetch Field Names |
| 68 | * |
| 69 | * Generates an array of column names |
| 70 | * |
| 71 | * @access public |
| 72 | * @return array |
| 73 | */ |
| 74 | function list_fields() |
| 75 | { |
| 76 | if ($this->db->db_debug) |
| 77 | { |
| 78 | return $this->db->display_error('db_unsuported_feature'); |
| 79 | } |
| 80 | return FALSE; |
| 81 | } |
| 82 | |
| 83 | // -------------------------------------------------------------------- |
| 84 | |
| 85 | /** |
| 86 | * Field data |
| 87 | * |
| 88 | * Generates an array of objects containing field meta-data |
| 89 | * |
| 90 | * @access public |
| 91 | * @return array |
| 92 | */ |
| 93 | function field_data() |
| 94 | { |
| 95 | $data = array(); |
| 96 | |
| 97 | try |
| 98 | { |
| 99 | for($i = 0; $i < $this->num_fields(); $i++) |
| 100 | { |
| 101 | $data[] = $this->result_id->getColumnMeta($i); |
| 102 | } |
| 103 | |
| 104 | return $data; |
| 105 | } |
| 106 | catch (Exception $e) |
| 107 | { |
| 108 | if ($this->db->db_debug) |
| 109 | { |
| 110 | return $this->db->display_error('db_unsuported_feature'); |
| 111 | } |
| 112 | return FALSE; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // -------------------------------------------------------------------- |
| 117 | |
| 118 | /** |
| 119 | * Free the result |
| 120 | * |
| 121 | * @return null |
| 122 | */ |
| 123 | function free_result() |
| 124 | { |
| 125 | if (is_object($this->result_id)) |
| 126 | { |
| 127 | $this->result_id = FALSE; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | // -------------------------------------------------------------------- |
| 132 | |
| 133 | /** |
| 134 | * Data Seek |
| 135 | * |
| 136 | * Moves the internal pointer to the desired offset. We call |
| 137 | * this internally before fetching results to make sure the |
| 138 | * result set starts at zero |
| 139 | * |
| 140 | * @access private |
| 141 | * @return array |
| 142 | */ |
| 143 | function _data_seek($n = 0) |
| 144 | { |
| 145 | return FALSE; |
| 146 | } |
| 147 | |
| 148 | // -------------------------------------------------------------------- |
| 149 | |
| 150 | /** |
| 151 | * Result - associative array |
| 152 | * |
| 153 | * Returns the result set as an array |
| 154 | * |
| 155 | * @access private |
| 156 | * @return array |
| 157 | */ |
| 158 | function _fetch_assoc() |
| 159 | { |
| 160 | return $this->result_id->fetch(PDO::FETCH_ASSOC); |
| 161 | } |
| 162 | |
| 163 | // -------------------------------------------------------------------- |
| 164 | |
| 165 | /** |
| 166 | * Result - object |
| 167 | * |
| 168 | * Returns the result set as an object |
| 169 | * |
| 170 | * @access private |
| 171 | * @return object |
| 172 | */ |
| 173 | function _fetch_object() |
| 174 | { |
| 175 | return $this->result_id->fetchObject(); |
| 176 | } |
| 177 | |
| 178 | } |
| 179 | |
| 180 | |
| 181 | /* End of file pdo_result.php */ |
| 182 | /* Location: ./system/database/drivers/pdo/pdo_result.php */ |