]>
src.bluestatic.org Git - isso.git/blob - DbMySql.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 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 2 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 (c)2005 - 2008, Blue Static
41 class BSDbMySql
extends BSDb
44 * Wrapper: mysql_connect
46 protected function _connect($server, $user, $password, $database)
48 $link = @mysql_connect($server, $user, $password, true);
51 $this->_selectDb($database, $link);
58 * Opens a connection to the specified database name
60 * @param string Database name
61 * @param integer DB-Link
63 private function _selectDb($database, $link)
65 if (!mysql_select_db($database, $link))
67 throw new BSDbException($this->_errorString(), $this->_errorNumber(), 'Cannot use the database ' . $database);
72 * Wrapper: mysql_query
74 protected function _query($string)
76 return mysql_query($string, $this->dblink
);
80 * Wrapper: mysql_escape_string
82 protected function _escapeBinary($binary)
84 return mysql_escape_string($binary);
88 * Wrapper: mysql(_real)_escape_string
90 protected function _escapeString($string)
92 if (function_exists('mysql_real_escape_string'))
94 return @mysql_real_escape_string($string, $this->dblink
);
98 return @mysql_escape_string($string);
103 * Not supported: unescape binary string
105 protected function _unescapeBinary($string)
111 * Wrapper: mysql_insert_id
113 protected function _insertId()
115 return mysql_insert_id($this->dblink
);
119 * Wrapper: mysql_affected_rows
121 protected function _affectedRows($result)
123 return mysql_affected_rows($this->dblink
);
127 * Starts a database transaction
129 public function begin()
131 $this->query("BEGIN WORK");
135 * Reverts a transaction back to a given savepoint
137 public function rollback()
139 $this->query("ROLLBACK");
143 * Commits a database transaction
145 public function commit()
147 $this->query("COMMIT");
151 * Returns the error number
153 * @return integer Error number
155 public function _errorNumber()
157 return mysql_errno($this->dblink
);
161 * Returns the error string
163 * @return string Error string
165 public function _errorString()
167 return mysql_error($this->dblink
);
174 * This class holds result information for a database result
177 * @copyright Copyright (c)2005 - 2008, Blue Static
181 class BSDbMySqlResult
extends BSDbResult
184 * Wrapper: mysql_fetch_assoc
186 protected function _fetchAssocArray($result)
188 return mysql_fetch_assoc($result);
192 * Wrapper: mysql_fetch_row
194 protected function _fetchRowArray($result)
196 return mysql_fetch_row($result);
200 * Wrapper: mysql_fetch_object
202 public function _fetchObject($result)
204 return mysql_fetch_object($result);
208 * Wrapper: mysql_free_result
210 protected function _freeResult($result)
212 mysql_free_result($result);
216 * Wrapper: mysql_num_rows
218 protected function _numRows($result)
220 return mysql_num_rows($result);