Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 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 | * |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
Andrey Andreev | c7db6bb | 2012-07-05 15:11:20 +0300 | [diff] [blame] | 24 | * @since Version 1.0 |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 25 | * @filesource |
| 26 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 28 | |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 29 | /** |
Alex Bilbie | 01ab004 | 2011-03-18 19:24:30 +0000 | [diff] [blame] | 30 | * SQLSRV Result Class |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 31 | * |
| 32 | * This class extends the parent result class: CI_DB_result |
| 33 | * |
| 34 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 35 | * @author EllisLab Dev Team |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 36 | * @link http://codeigniter.com/user_guide/database/ |
Andrey Andreev | c7db6bb | 2012-07-05 15:11:20 +0300 | [diff] [blame] | 37 | * @since 2.0.3 |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 38 | */ |
Alex Bilbie | 01ab004 | 2011-03-18 19:24:30 +0000 | [diff] [blame] | 39 | class CI_DB_sqlsrv_result extends CI_DB_result { |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Number of rows in the result set |
| 43 | * |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 44 | * @return int |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 45 | */ |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 46 | public function num_rows() |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 47 | { |
Andrey Andreev | c7db6bb | 2012-07-05 15:11:20 +0300 | [diff] [blame] | 48 | return is_int($this->num_rows) |
| 49 | ? $this->num_rows |
| 50 | : $this->num_rows = @sqlsrv_num_rows($this->result_id); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | // -------------------------------------------------------------------- |
| 54 | |
| 55 | /** |
| 56 | * Number of fields in the result set |
| 57 | * |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 58 | * @return int |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 59 | */ |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 60 | public function num_fields() |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 61 | { |
Alex Bilbie | 079069c | 2011-03-10 19:36:58 +0000 | [diff] [blame] | 62 | return @sqlsrv_num_fields($this->result_id); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | // -------------------------------------------------------------------- |
| 66 | |
| 67 | /** |
| 68 | * Fetch Field Names |
| 69 | * |
| 70 | * Generates an array of column names |
| 71 | * |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 72 | * @return array |
| 73 | */ |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 74 | public function list_fields() |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 75 | { |
| 76 | $field_names = array(); |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 77 | foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field) |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 78 | { |
Alex Bilbie | 3a43c7a | 2011-03-18 19:48:04 +0000 | [diff] [blame] | 79 | $field_names[] = $field['Name']; |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 80 | } |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 81 | |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 82 | return $field_names; |
| 83 | } |
| 84 | |
| 85 | // -------------------------------------------------------------------- |
| 86 | |
| 87 | /** |
| 88 | * Field data |
| 89 | * |
| 90 | * Generates an array of objects containing field meta-data |
| 91 | * |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 92 | * @return array |
| 93 | */ |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 94 | public function field_data() |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 95 | { |
| 96 | $retval = array(); |
Andrey Andreev | f1e1b77 | 2012-11-16 01:27:00 +0200 | [diff] [blame^] | 97 | foreach (sqlsrv_field_metadata($this->result_id) as $i => $field) |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 98 | { |
Andrey Andreev | f1e1b77 | 2012-11-16 01:27:00 +0200 | [diff] [blame^] | 99 | $retval[$i] = new stdClass(); |
| 100 | $retval[$i]->name = $field['Name']; |
| 101 | $retval[$i]->type = $field['Type']; |
| 102 | $retval[$i]->max_length = $field['Size']; |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 103 | } |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 104 | |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 105 | return $retval; |
| 106 | } |
| 107 | |
| 108 | // -------------------------------------------------------------------- |
| 109 | |
| 110 | /** |
| 111 | * Free the result |
| 112 | * |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 113 | * @return void |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 114 | */ |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 115 | public function free_result() |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 116 | { |
| 117 | if (is_resource($this->result_id)) |
| 118 | { |
Alex Bilbie | 079069c | 2011-03-10 19:36:58 +0000 | [diff] [blame] | 119 | sqlsrv_free_stmt($this->result_id); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 120 | $this->result_id = FALSE; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // -------------------------------------------------------------------- |
| 125 | |
| 126 | /** |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 127 | * Result - associative array |
| 128 | * |
| 129 | * Returns the result set as an array |
| 130 | * |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 131 | * @return array |
| 132 | */ |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 133 | protected function _fetch_assoc() |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 134 | { |
Alex Bilbie | 079069c | 2011-03-10 19:36:58 +0000 | [diff] [blame] | 135 | return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | // -------------------------------------------------------------------- |
| 139 | |
| 140 | /** |
| 141 | * Result - object |
| 142 | * |
| 143 | * Returns the result set as an object |
| 144 | * |
Andrey Andreev | 8463b91 | 2012-11-02 02:16:28 +0200 | [diff] [blame] | 145 | * @param string $class_name |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 146 | * @return object |
| 147 | */ |
Andrey Andreev | 9a4f356 | 2012-07-06 11:57:37 +0300 | [diff] [blame] | 148 | protected function _fetch_object($class_name = 'stdClass') |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 149 | { |
Andrey Andreev | 9a4f356 | 2012-07-06 11:57:37 +0300 | [diff] [blame] | 150 | return sqlsrv_fetch_object($this->result_id, $class_name); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | } |
| 154 | |
Andrey Andreev | 0e8968a | 2012-01-26 02:04:37 +0200 | [diff] [blame] | 155 | /* End of file sqlsrv_result.php */ |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 156 | /* Location: ./system/database/drivers/sqlsrv/sqlsrv_result.php */ |