Database results are now independent objects as opposed to being a resource identifie...
[isso.git] / DbMySqlI.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2002-2007 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * MySQLi Database Layer (DbMySqlI.php)
24 *
25 * @package ISSO
26 */
27
28 require_once('ISSO/Db.php');
29
30 /**
31 * MySQLi Database Layer
32 *
33 * This framework is a function wrapper for MySQLi functions so we can have
34 * better error reporting and query reporting.
35 *
36 * @author Blue Static
37 * @copyright Copyright (c)2002 - 2007, Blue Static
38 * @package ISSO
39 *
40 */
41 class BSDbMySqlI extends BSDb
42 {
43 // ###################################################################
44 /**
45 * Wrapper: mysql_connect
46 */
47 protected function _connect($server, $user, $password, $database)
48 {
49 return @mysqli_connect($server, $user, $password, $database);
50 }
51
52 // ###################################################################
53 /**
54 * Wrapper: mysql_query
55 */
56 protected function _query($string)
57 {
58 return mysqli_query($this->dblink, $string);
59 }
60
61 // ###################################################################
62 /**
63 * Wrapper: mysql_escape_string
64 */
65 protected function _escapeBinary($binary)
66 {
67 return mysqli_real_escape_string($this->dblink, $binary);
68 }
69
70 // ###################################################################
71 /**
72 * Wrapper: mysql(_real)_escape_string
73 */
74 protected function _escapeString($string)
75 {
76 return mysqli_real_escape_string($this->dblink, $string);
77 }
78
79 // ###################################################################
80 /**
81 * Not supported: unescape binary string
82 */
83 protected function _unescapeBinary($string)
84 {
85 return $string;
86 }
87
88 // ###################################################################
89 /**
90 * Starts a database transaction
91 */
92 public function begin()
93 {
94 $this->query("START TRANSACTION");
95 }
96
97 // ###################################################################
98 /**
99 * Reverts a transaction back to a given savepoint
100 */
101 public function rollback()
102 {
103 $this->query("ROLLBACK");
104 }
105
106 // ###################################################################
107 /**
108 * Commits a database transaction
109 */
110 public function commit()
111 {
112 $this->query("COMMIT");
113 }
114
115 // ###################################################################
116 /**
117 * Returns the error number
118 *
119 * @return integer Error number
120 */
121 public function _errorNumber()
122 {
123 return mysqli_errno($this->dblink);
124 }
125
126 // ###################################################################
127 /**
128 * Returns the error string
129 *
130 * @return string Error string
131 */
132 public function _errorString()
133 {
134 return mysqli_error($this->dblink);
135 }
136 }
137
138 /**
139 * Database Result
140 *
141 * This class holds result information for a database result
142 *
143 * @author rsesek
144 * @copyright Copyright (c)2002 - 2007, Blue Static
145 * @package ISSO
146 *
147 */
148 class BSDbMySqlIResult extends BSDbResult
149 {
150 // ###################################################################
151 /**
152 * Wrapper: mysql_fetch_assoc
153 */
154 protected function _fetchAssocArray($result)
155 {
156 return mysqli_fetch_assoc($result);
157 }
158
159 // ###################################################################
160 /**
161 * Wrapper: mysql_fetch_row
162 */
163 protected function _fetchRowArray($result)
164 {
165 return mysqli_fetch_row($result);
166 }
167
168 // ###################################################################
169 /**
170 * Wrapper: mysql_fetch_object
171 */
172 public function _fetchObject($result)
173 {
174 return mysqli_fetch_object($result);
175 }
176
177 // ###################################################################
178 /**
179 * Wrapper: mysql_free_result
180 */
181 protected function _freeResult($result)
182 {
183 mysqli_free_result($result);
184 }
185
186 // ###################################################################
187 /**
188 * Wrapper: mysql_insert_id
189 */
190 protected function _insertId()
191 {
192 return mysqli_insert_id($this->dblink);
193 }
194
195 // ###################################################################
196 /**
197 * Wrapper: mysql_num_rows
198 */
199 protected function _numRows($result)
200 {
201 return mysqli_num_rows($result);
202 }
203
204 // ###################################################################
205 /**
206 * Wrapper: mysql_affected_rows
207 */
208 protected function _affectedRows($result)
209 {
210 return mysqli_affected_rows($this->dblink);
211 }
212 }
213
214 ?>