carbonPHP Initial commit v2.0
[carbonphp.git] / Source / carbon / database / Database_result.php
blobe64c71655003ef40f553f327136e25a85cff9907
1 <?php
2 /*------------------------------------------------------------
3 * CarbonPHP framework (C) Tom Bell
4 * http://tombell.org.uk
5 *------------------------------------------------------------*/
7 if (!defined('CARBON_PATH'))
9 exit('Direct script access is not allowed.');
12 class Carbon_Database_result
14 public $conn_id = null;
15 public $result_id = null;
16 public $result_array = array();
17 public $result_object = array();
18 public $current_row = 0;
19 public $num_rows = 0;
21 public function result($type = 'object')
23 return ($type == 'object') ? $this->result_object() : $this->result_array();
26 public function result_object()
28 if (count($this->result_object) > 0)
30 return $this->result_object;
33 if ($this->result_id === false || $this->num_rows() == 0)
35 return array();
38 $this->database_data_seek(0);
40 while($row = $this->database_fetch_object())
42 $this->result_object[] = $row;
45 return $this->result_object;
48 public function result_array()
50 if (count($this->result_array) > 0)
52 return $this->result_array;
55 if ($this->result_id === false || $this->num_rows() == 0)
57 return array();
60 $this->database_data_seek(0);
62 while ($row = $this->database_fetch_assoc())
64 $this->result_array[] = $row;
67 return $this->result_array;
70 public function row($index = 0, $type = 'object')
72 return ($type == 'object') ? $this->row_object($index) : $this->row_array($index);
75 public function row_object($index = 0)
77 $result = $this->result_object();
79 if (count($result) == 0)
81 return $result;
84 if ($index != $this->current_row && isset($result[$index]))
86 $this->current_row = $index;
89 return $result[$this->current_row];
92 public function row_array($index = 0)
94 $result = $this->result_array();
96 if (count($result) == 0)
98 return $result;
101 if ($index != $this->current_row && isset($result[$index]))
103 $this->current_row = $index;
106 return $result[$this->current_row];
109 public function first_row($type = 'object')
111 $result = $this->result($type);
113 if (count($result) == 0)
115 return $result;
118 return $result[0];
121 public function last_row($type = 'object')
123 $result = $this->result($type);
125 if (count($result) == 0)
127 return $result;
130 return $result[count($result) - 1];
133 public function next_row($type = 'object')
135 $result = $this->result($type);
137 if (count($result) == 0)
139 return $result;
142 if (isset($result[$this->current_row + 1]))
144 $this->current_row++;
147 return $result[$this->current_row];
150 public function previous_row($type = 'object')
152 $result = $this->result($type);
154 if (count($result) == 0)
156 return $result;
159 if (isset($result[$this->current_row - 1]))
161 $this->current_row--;
164 return $result[$this->current_row];
167 public function num_rows()
169 return $this->num_rows;
172 public function num_fields()
174 return 0;
177 public function list_fields()
179 return array();
182 public function field_data()
184 return array();
187 public function free_result()
189 return true;
192 public function database_data_seek()
194 return true;
197 public function database_fetch_assoc()
199 return array();
202 public function database_fetch_object()
204 return array();