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;
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)
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)
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)
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)
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)
121 public function last_row($type = 'object')
123 $result = $this->result($type);
125 if (count($result) == 0)
130 return $result[count($result) - 1];
133 public function next_row($type = 'object')
135 $result = $this->result($type);
137 if (count($result) == 0)
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)
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()
177 public function list_fields()
182 public function field_data()
187 public function free_result()
192 public function database_data_seek()
197 public function database_fetch_assoc()
202 public function database_fetch_object()