]> src.bluestatic.org Git - isso.git/blob - DbMySql.php
Adding fixes in the unit tests for all the refactoring we did
[isso.git] / DbMySql.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 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 * MySQL Database Layer (DbMySql.php)
24 *
25 * @package ISSO
26 */
27
28 require_once(ISSO . '/Db.php');
29
30 /**
31 * MySQL Database Layer
32 *
33 * This framework is a function wrapper for MySQL functions so we can have
34 * better error reporting and query reporting.
35 *
36 * @author Blue Static
37 * @copyright Copyright (c)2005 - 2008, Blue Static
38 * @package ISSO
39 *
40 */
41 class BSDbMySql extends BSDb
42 {
43 // ###################################################################
44 /**
45 * Wrapper: mysql_connect
46 */
47 protected function _connect($server, $user, $password, $database)
48 {
49 $link = @mysql_connect($server, $user, $password, true);
50 if ($link)
51 {
52 $this->_selectDb($database, $link);
53 }
54
55 return $link;
56 }
57
58 // ###################################################################
59 /**
60 * Opens a connection to the specified database name
61 *
62 * @param string Database name
63 * @param integer DB-Link
64 */
65 private function _selectDb($database, $link)
66 {
67 if (!mysql_select_db($database, $link))
68 {
69 throw new BSDbException($this->_errorString(), $this->_errorNumber(), 'Cannot use the database ' . $database);
70 }
71 }
72
73 // ###################################################################
74 /**
75 * Wrapper: mysql_query
76 */
77 protected function _query($string)
78 {
79 return mysql_query($string, $this->dblink);
80 }
81
82 // ###################################################################
83 /**
84 * Wrapper: mysql_escape_string
85 */
86 protected function _escapeBinary($binary)
87 {
88 return mysql_escape_string($binary);
89 }
90
91 // ###################################################################
92 /**
93 * Wrapper: mysql(_real)_escape_string
94 */
95 protected function _escapeString($string)
96 {
97 if (function_exists('mysql_real_escape_string'))
98 {
99 return @mysql_real_escape_string($string, $this->dblink);
100 }
101 else
102 {
103 return @mysql_escape_string($string);
104 }
105 }
106
107 // ###################################################################
108 /**
109 * Not supported: unescape binary string
110 */
111 protected function _unescapeBinary($string)
112 {
113 return $string;
114 }
115
116 // ###################################################################
117 /**
118 * Wrapper: mysql_insert_id
119 */
120 protected function _insertId()
121 {
122 return mysql_insert_id($this->dblink);
123 }
124
125 // ###################################################################
126 /**
127 * Wrapper: mysql_affected_rows
128 */
129 protected function _affectedRows($result)
130 {
131 return mysql_affected_rows($this->dblink);
132 }
133
134 // ###################################################################
135 /**
136 * Starts a database transaction
137 */
138 public function begin()
139 {
140 $this->query("BEGIN WORK");
141 }
142
143 // ###################################################################
144 /**
145 * Reverts a transaction back to a given savepoint
146 */
147 public function rollback()
148 {
149 $this->query("ROLLBACK");
150 }
151
152 // ###################################################################
153 /**
154 * Commits a database transaction
155 */
156 public function commit()
157 {
158 $this->query("COMMIT");
159 }
160
161 // ###################################################################
162 /**
163 * Returns the error number
164 *
165 * @return integer Error number
166 */
167 public function _errorNumber()
168 {
169 return mysql_errno($this->dblink);
170 }
171
172 // ###################################################################
173 /**
174 * Returns the error string
175 *
176 * @return string Error string
177 */
178 public function _errorString()
179 {
180 return mysql_error($this->dblink);
181 }
182 }
183
184 /**
185 * Database Result
186 *
187 * This class holds result information for a database result
188 *
189 * @author rsesek
190 * @copyright Copyright (c)2005 - 2008, Blue Static
191 * @package ISSO
192 *
193 */
194 class BSDbMySqlResult extends BSDbResult
195 {
196 // ###################################################################
197 /**
198 * Wrapper: mysql_fetch_assoc
199 */
200 protected function _fetchAssocArray($result)
201 {
202 return mysql_fetch_assoc($result);
203 }
204
205 // ###################################################################
206 /**
207 * Wrapper: mysql_fetch_row
208 */
209 protected function _fetchRowArray($result)
210 {
211 return mysql_fetch_row($result);
212 }
213
214 // ###################################################################
215 /**
216 * Wrapper: mysql_fetch_object
217 */
218 public function _fetchObject($result)
219 {
220 return mysql_fetch_object($result);
221 }
222
223 // ###################################################################
224 /**
225 * Wrapper: mysql_free_result
226 */
227 protected function _freeResult($result)
228 {
229 mysql_free_result($result);
230 }
231
232 // ###################################################################
233 /**
234 * Wrapper: mysql_num_rows
235 */
236 protected function _numRows($result)
237 {
238 return mysql_num_rows($result);
239 }
240 }
241
242 ?>