Use (c) instead of the actual copyright symbol to avoid the really annoying character...
[isso.git] / DbMySql.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 * 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)2002 - 2007, 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_fetch_assoc
119 */
120 protected function _fetchAssocArray($result)
121 {
122 return mysql_fetch_assoc($result);
123 }
124
125 // ###################################################################
126 /**
127 * Wrapper: mysql_fetch_row
128 */
129 protected function _fetchRowArray($result)
130 {
131 return mysql_fetch_row($result);
132 }
133
134 // ###################################################################
135 /**
136 * Wrapper: mysql_fetch_object
137 */
138 public function _fetchObject($result)
139 {
140 return mysql_fetch_object($result);
141 }
142
143 // ###################################################################
144 /**
145 * Wrapper: mysql_free_result
146 */
147 protected function _freeResult($result)
148 {
149 mysql_free_result($result);
150 }
151
152 // ###################################################################
153 /**
154 * Wrapper: mysql_insert_id
155 */
156 protected function _insertId()
157 {
158 return mysql_insert_id($this->dblink);
159 }
160
161 // ###################################################################
162 /**
163 * Wrapper: mysql_num_rows
164 */
165 protected function _numRows($result)
166 {
167 return mysql_num_rows($result);
168 }
169
170 // ###################################################################
171 /**
172 * Wrapper: mysql_affected_rows
173 */
174 protected function _affectedRows($result)
175 {
176 return mysql_affected_rows($this->dblink);
177 }
178
179 // ###################################################################
180 /**
181 * Starts a database transaction
182 */
183 public function begin()
184 {
185 $this->query("BEGIN WORK");
186 }
187
188
189 // ###################################################################
190 /**
191 * Reverts a transaction back to a given savepoint
192 */
193 public function rollback()
194 {
195 $this->query("ROLLBACK");
196 }
197
198 // ###################################################################
199 /**
200 * Commits a database transaction
201 */
202 public function commit()
203 {
204 $this->query("COMMIT");
205 }
206
207 // ###################################################################
208 /**
209 * Returns the error number
210 *
211 * @return integer Error number
212 */
213 public function _errorNumber()
214 {
215 return mysql_errno($this->dblink);
216 }
217
218 // ###################################################################
219 /**
220 * Returns the error string
221 *
222 * @return string Error string
223 */
224 public function _errorString()
225 {
226 return mysql_error($this->dblink);
227 }
228 }
229
230 ?>