]>
src.bluestatic.org Git - isso.git/blob - db_mysql.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
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 Abstraction 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);
51 $this->_selectDb($database, $link);
56 // ###################################################################
58 * Wrapper: mysql_pconnect
60 protected function _pConnect($server, $user, $password, $database)
62 $link = mysql_pconnect($server, $user, $password);
63 $this->select_db($database, $link);
68 // ###################################################################
70 * Opens a connection to the specified database name
72 * @param string Database name
73 * @param integer DB-Link
75 private function _selectDb($database, $link)
77 if (!mysql_select_db($database, $link))
79 $this->_error('Cannot use the database "' . $database . '"');
83 // ###################################################################
85 * Wrapper: mysql_query
87 protected function _query($string)
89 return mysql_query($string, $this->dblink
);
92 // ###################################################################
94 * Wrapper: mysql_escape_string
96 protected function _escapeBinary($binary)
98 return mysql_escape_string($binary);
101 // ###################################################################
103 * Wrapper: mysql(_real)_escape_string
105 protected function _escapeString($string)
107 if (function_exists('mysql_real_escape_string'))
109 return @mysql_real_escape_string($string, $this->dblink
);
113 return @mysql_escape_string($string);
117 // ###################################################################
119 * Not supported: unescape binary string
121 protected function _unescapeBinary($string)
126 // ###################################################################
128 * Wrapper: mysql_fetch_assoc
130 protected function _fetchAssocArray($result)
132 return mysql_fetch_assoc($result);
135 // ###################################################################
137 * Wrapper: mysql_fetch_row
139 protected function _fetchRowArray($result)
141 return mysql_fetch_row($result);
144 // ###################################################################
146 * Wrapper: mysql_fetch_object
148 public function _fetchObject($result)
150 return mysql_fetch_object($result);
153 // ###################################################################
155 * Wrapper: mysql_free_result
157 protected function _freeResult($result)
159 mysql_free_result($result);
162 // ###################################################################
164 * Wrapper: mysql_insert_id
166 protected function _insertId()
168 return mysql_insert_id($this->dblink
);
171 // ###################################################################
173 * Wrapper: mysql_num_rows
175 protected function _numRows($result)
177 return mysql_num_rows($result);
180 // ###################################################################
182 * Wrapper: mysql_affected_rows
184 protected function _affectedRows($result)
186 return mysql_affected_rows($result);
189 // ###################################################################
191 * Starts a database transaction
193 public function transaction_start()
195 $this->query("BEGIN WORK");
198 // ###################################################################
200 * Saves current transaction steps as a savepoint
202 * @param string Named savepoint
204 public function transaction_savepoint($name)
206 $this->query("SAVEPOINT $name");
209 // ###################################################################
211 * Reverts a transaction back to a given savepoint
213 * @param string Named savepoint
215 public function transaction_rollback($name = null)
217 $this->query("ROLLBACK
" . ($name != null ? " TO SAVEPOINT
$name" : ""));
220 // ###################################################################
222 * Commits a database transaction
224 public function transaction_commit()
226 $this->query("COMMIT");
230 /*=====================================================================*\
231 || ###################################################################
234 || ###################################################################
235 \*=====================================================================*/