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 Abstraction Layer
29 $this->load('db', null
);
32 * MySQL Database Abstraction Layer
34 * This framework is a function wrapper for MySQL functions so we can have
35 * better error reporting and query reporting.
38 * @copyright Copyright ©2002 - [#]year[#], Blue Static
43 class DB_MySQL
extends DB_Abstract
46 * Command mapping list
50 var $commands = array(
51 'pconnect' => '$this->command_mysql_pconnect',
52 'connect' => '$this->command_mysql_connect',
53 'query' => '$this->command_mysql_query',
54 'error_num' => 'mysql_errno',
55 'error_str' => 'mysql_error',
56 'escape_string' => '$this->command_mysql_escape_string',
57 'escape_binary' => '$this->escape_binary',
58 'fetch_assoc' => 'mysql_fetch_assoc',
59 'fetch_row' => 'mysql_fetch_row',
60 'fetch_object' => 'mysql_fetch_object',
61 'free_result' => 'mysql_free_result',
62 'insert_id' => 'mysql_insert_id',
63 'num_rows' => 'mysql_num_rows',
64 'affected_rows' => 'mysql_affected_rows'
67 // ###################################################################
71 function __construct(&$registry)
73 parent
::__construct($registry);
76 // ###################################################################
80 function DB_MySQL(&$registry)
82 $this->__construct($registry);
85 // ###################################################################
87 * Wrapper: mysql_pconnect
91 * @param string Server name
92 * @param string User name
93 * @param string Password
94 * @param string Database
96 * @return integer DB-Link
98 function command_mysql_pconnect($server, $user, $password, $database)
100 $link = mysql_pconnect($server, $user, $password);
101 $this->select_db($database, $link);
106 // ###################################################################
108 * Wrapper: mysql_connect
112 * @param string Server name
113 * @param string User name
114 * @param string Password
115 * @param string Database
117 * @return integer DB-Link
119 function command_mysql_connect($server, $user, $password, $database)
121 $link = mysql_connect($server, $user, $password);
122 $this->select_db($database, $link);
127 // ###################################################################
129 * Wrapper: mysql_select_db
133 * @param string Database name
134 * @param integer DB-Link
136 function select_db($database, $link)
138 if (!mysql_select_db($database, $link))
140 $this->error('Cannot use the database \'' . $this->database
. '\'');
144 // ###################################################################
146 * Wrapper: mysql_query
150 * @param integer DB-Link
151 * @param string Query string
153 * @return integer Result
155 function command_mysql_query($link, $string)
157 return mysql_query($string, $link);
160 // ###################################################################
162 * Escapes a binary string for insertion into the database
166 * @param string Unescaped data
168 * @return string Escaped binary data
170 function escape_binary($binary)
172 return mysql_escape_string($binary);
175 // ###################################################################
177 * Wrapper: mysql(_real)_escape_string
181 * @param integer DB-Link
182 * @param string Unescaped text
184 * @return string Escaped text
186 function command_mysql_escape_string($link, $string)
188 if (function_exists('mysql_real_escape_string'))
190 return @mysql_real_escape_string($string, $link);
194 return @mysql_escape_string($string);
198 // ###################################################################
200 * Not supported: unescape binary string
204 * @param string Escaped data
206 * @return string Same data
208 function command_unescape_binary($string)
213 // ###################################################################
215 * Starts a database transaction
219 function transaction_start()
221 $this->query("BEGIN WORK");
224 // ###################################################################
226 * Saves current transaction steps as a savepoint
230 * @param string Named savepoint
232 function transaction_savepoint($name)
234 $this->query("SAVEPOINT $name");
237 // ###################################################################
239 * Reverts a transaction back to a given savepoint
243 * @param string Named savepoint
245 function transaction_rollback($name = null
)
247 $this->query("ROLLBACK" . ($name != null ?
" TO SAVEPOINT $name" : ""));
250 // ###################################################################
252 * Commits a database transaction
256 function transaction_commit()
258 $this->query("COMMIT");
262 /*=====================================================================*\
263 || ###################################################################
266 || ###################################################################
267 \*=====================================================================*/