2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright ©2002-[#]year[#] Blue Static
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.
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
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 \*=====================================================================*/
23 * MySQL Database Layer (DbMySql.php)
28 require_once('ISSO/Db.php');
31 * MySQL Database Layer
33 * This framework is a function wrapper for MySQL functions so we can have
34 * better error reporting and query reporting.
37 * @copyright Copyright ©2002 - [#]year[#], Blue Static
42 class BSDbMySql
extends BSDb
44 // ###################################################################
46 * Wrapper: mysql_connect
48 protected function _connect($server, $user, $password, $database)
50 $link = @mysql_connect($server, $user, $password, true
);
53 $this->_selectDb($database, $link);
59 // ###################################################################
61 * Opens a connection to the specified database name
63 * @param string Database name
64 * @param integer DB-Link
66 private function _selectDb($database, $link)
68 if (!mysql_select_db($database, $link))
70 throw new BSDbException($this->_errorString(), $this->_errorNumber(), 'Cannot use the database ' . $database);
71 $this->_error('Cannot use the database "' . $database . '"');
75 // ###################################################################
77 * Wrapper: mysql_query
79 protected function _query($string)
81 return mysql_query($string, $this->dblink
);
84 // ###################################################################
86 * Wrapper: mysql_escape_string
88 protected function _escapeBinary($binary)
90 return mysql_escape_string($binary);
93 // ###################################################################
95 * Wrapper: mysql(_real)_escape_string
97 protected function _escapeString($string)
99 if (function_exists('mysql_real_escape_string'))
101 return @mysql_real_escape_string($string, $this->dblink
);
105 return @mysql_escape_string($string);
109 // ###################################################################
111 * Not supported: unescape binary string
113 protected function _unescapeBinary($string)
118 // ###################################################################
120 * Wrapper: mysql_fetch_assoc
122 protected function _fetchAssocArray($result)
124 return mysql_fetch_assoc($result);
127 // ###################################################################
129 * Wrapper: mysql_fetch_row
131 protected function _fetchRowArray($result)
133 return mysql_fetch_row($result);
136 // ###################################################################
138 * Wrapper: mysql_fetch_object
140 public function _fetchObject($result)
142 return mysql_fetch_object($result);
145 // ###################################################################
147 * Wrapper: mysql_free_result
149 protected function _freeResult($result)
151 mysql_free_result($result);
154 // ###################################################################
156 * Wrapper: mysql_insert_id
158 protected function _insertId()
160 return mysql_insert_id($this->dblink
);
163 // ###################################################################
165 * Wrapper: mysql_num_rows
167 protected function _numRows($result)
169 return mysql_num_rows($result);
172 // ###################################################################
174 * Wrapper: mysql_affected_rows
176 protected function _affectedRows($result)
178 return mysql_affected_rows($this->dblink
);
181 // ###################################################################
183 * Starts a database transaction
185 public function transactionStart()
187 $this->query("BEGIN WORK");
190 // ###################################################################
192 * Saves current transaction steps as a savepoint
194 * @param string Named savepoint
196 public function transactionSavepoint($name)
198 $this->query("SAVEPOINT $name");
201 // ###################################################################
203 * Reverts a transaction back to a given savepoint
205 * @param string Named savepoint
207 public function transactionRollback($name = null
)
209 $this->query("ROLLBACK" . ($name != null ?
" TO SAVEPOINT $name" : ""));
212 // ###################################################################
214 * Commits a database transaction
216 public function transactionCommit()
218 $this->query("COMMIT");
221 // ###################################################################
223 * Returns the error number
225 * @return integer Error number
227 public function _errorNumber()
229 return mysql_errno($this->dblink
);
232 // ###################################################################
234 * Returns the error string
236 * @return string Error string
238 public function _errorString()
240 return mysql_error($this->dblink
);
244 /*=====================================================================*\
245 || ###################################################################
248 || ###################################################################
249 \*=====================================================================*/