Merging changes from the 2.1.x branch back to trunk (r860-862)
[isso.git] / DbMySqlI.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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 ©2002 - [#]year[#], Blue Static
38 * @version $Revision$
39 * @package ISSO
40 *
41 */
42 class BSDbMySqlI extends BSDb
43 {
44 // ###################################################################
45 /**
46 * Wrapper: mysql_connect
47 */
48 protected function _connect($server, $user, $password, $database)
49 {
50 return mysqli_connect($server, $user, $password, $database);
51 }
52
53 // ###################################################################
54 /**
55 * Wrapper: mysql_pconnect
56 */
57 protected function _pConnect($server, $user, $password, $database)
58 {
59 return mysqli_connect($server, $user, $password, $database);
60 }
61
62 // ###################################################################
63 /**
64 * Wrapper: mysql_query
65 */
66 protected function _query($string)
67 {
68 return mysqli_query($this->dblink, $string);
69 }
70
71 // ###################################################################
72 /**
73 * Wrapper: mysql_escape_string
74 */
75 protected function _escapeBinary($binary)
76 {
77 return mysqli_real_escape_string($this->dblink, $binary);
78 }
79
80 // ###################################################################
81 /**
82 * Wrapper: mysql(_real)_escape_string
83 */
84 protected function _escapeString($string)
85 {
86 return mysqli_real_escape_string($this->dblink, $string);
87 }
88
89 // ###################################################################
90 /**
91 * Not supported: unescape binary string
92 */
93 protected function _unescapeBinary($string)
94 {
95 return $string;
96 }
97
98 // ###################################################################
99 /**
100 * Wrapper: mysql_fetch_assoc
101 */
102 protected function _fetchAssocArray($result)
103 {
104 return mysqli_fetch_assoc($result);
105 }
106
107 // ###################################################################
108 /**
109 * Wrapper: mysql_fetch_row
110 */
111 protected function _fetchRowArray($result)
112 {
113 return mysqli_fetch_row($result);
114 }
115
116 // ###################################################################
117 /**
118 * Wrapper: mysql_fetch_object
119 */
120 public function _fetchObject($result)
121 {
122 return mysqli_fetch_object($result);
123 }
124
125 // ###################################################################
126 /**
127 * Wrapper: mysql_free_result
128 */
129 protected function _freeResult($result)
130 {
131 mysqli_free_result($result);
132 }
133
134 // ###################################################################
135 /**
136 * Wrapper: mysql_insert_id
137 */
138 protected function _insertId()
139 {
140 return mysqli_insert_id($this->dblink);
141 }
142
143 // ###################################################################
144 /**
145 * Wrapper: mysql_num_rows
146 */
147 protected function _numRows($result)
148 {
149 return mysqli_num_rows($result);
150 }
151
152 // ###################################################################
153 /**
154 * Wrapper: mysql_affected_rows
155 */
156 protected function _affectedRows($result)
157 {
158 return mysqli_affected_rows($this->dblink);
159 }
160
161 // ###################################################################
162 /**
163 * Starts a database transaction
164 */
165 public function transactionStart()
166 {
167 $this->query("START TRANSACTION");
168 }
169
170 // ###################################################################
171 /**
172 * Saves current transaction steps as a savepoint
173 *
174 * @param string Named savepoint
175 */
176 public function transactionSavepoint($name)
177 {
178 $this->query("SAVEPOINT $name");
179 }
180
181 // ###################################################################
182 /**
183 * Reverts a transaction back to a given savepoint
184 *
185 * @param string Named savepoint
186 */
187 public function transactionRollback($name = null)
188 {
189 $this->query("ROLLBACK" . ($name != null ? " TO SAVEPOINT $name" : ""));
190 }
191
192 // ###################################################################
193 /**
194 * Commits a database transaction
195 */
196 public function transactionCommit()
197 {
198 $this->query("COMMIT");
199 }
200
201 // ###################################################################
202 /**
203 * Returns the error number
204 *
205 * @return integer Error number
206 */
207 public function _errorNumber()
208 {
209 return mysqli_errno($this->dblink);
210 }
211
212 // ###################################################################
213 /**
214 * Returns the error string
215 *
216 * @return string Error string
217 */
218 public function _errorString()
219 {
220 return mysqli_error($this->dblink);
221 }
222 }
223
224 /*=====================================================================*\
225 || ###################################################################
226 || # $HeadURL$
227 || # $Id$
228 || ###################################################################
229 \*=====================================================================*/
230 ?>