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 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
49 private $commands = array(
50 'pconnect' => '$this->command_mysql_pconnect',
51 'connect' => '$this->command_mysql_connect',
52 'query' => '$this->command_mysql_query',
53 'error_num' => 'mysql_errno',
54 'error_str' => 'mysql_error',
55 'escape_string' => '$this->command_mysql_escape_string',
56 'escape_binary' => '$this->escape_binary',
57 'fetch_assoc' => 'mysql_fetch_assoc',
58 'fetch_row' => 'mysql_fetch_row',
59 'fetch_object' => 'mysql_fetch_object',
60 'free_result' => 'mysql_free_result',
61 'insert_id' => 'mysql_insert_id',
62 'num_rows' => 'mysql_num_rows',
63 'affected_rows' => 'mysql_affected_rows'
66 // ###################################################################
70 function __construct(&$registry)
72 parent
::__construct($registry);
75 // ###################################################################
77 * Wrapper: mysql_pconnect
81 * @param string Server name
82 * @param string User name
83 * @param string Password
84 * @param string Database
86 * @return integer DB-Link
88 function command_mysql_pconnect($server, $user, $password, $database)
90 $link = mysql_pconnect($server, $user, $password);
91 $this->select_db($database, $link);
96 // ###################################################################
98 * Wrapper: mysql_connect
102 * @param string Server name
103 * @param string User name
104 * @param string Password
105 * @param string Database
107 * @return integer DB-Link
109 function command_mysql_connect($server, $user, $password, $database)
111 $link = mysql_connect($server, $user, $password);
112 $this->select_db($database, $link);
117 // ###################################################################
119 * Wrapper: mysql_select_db
123 * @param string Database name
124 * @param integer DB-Link
126 function select_db($database, $link)
128 if (!mysql_select_db($database, $link))
130 $this->error('Cannot use the database \'' . $this->database
. '\'');
134 // ###################################################################
136 * Wrapper: mysql_query
140 * @param integer DB-Link
141 * @param string Query string
143 * @return integer Result
145 function command_mysql_query($link, $string)
147 return mysql_query($string, $link);
150 // ###################################################################
152 * Escapes a binary string for insertion into the database
156 * @param string Unescaped data
158 * @return string Escaped binary data
160 function escape_binary($binary)
162 return mysql_escape_string($binary);
165 // ###################################################################
167 * Wrapper: mysql(_real)_escape_string
171 * @param integer DB-Link
172 * @param string Unescaped text
174 * @return string Escaped text
176 function command_mysql_escape_string($link, $string)
178 if (function_exists('mysql_real_escape_string'))
180 return @mysql_real_escape_string($string, $link);
184 return @mysql_escape_string($string);
188 // ###################################################################
190 * Not supported: unescape binary string
194 * @param string Escaped data
196 * @return string Same data
198 function command_unescape_binary($string)
203 // ###################################################################
205 * Starts a database transaction
209 function transaction_start()
211 $this->query("BEGIN WORK");
214 // ###################################################################
216 * Saves current transaction steps as a savepoint
220 * @param string Named savepoint
222 function transaction_savepoint($name)
224 $this->query("SAVEPOINT $name");
227 // ###################################################################
229 * Reverts a transaction back to a given savepoint
233 * @param string Named savepoint
235 function transaction_rollback($name = null
)
237 $this->query("ROLLBACK" . ($name != null ?
" TO SAVEPOINT $name" : ""));
240 // ###################################################################
242 * Commits a database transaction
246 function transaction_commit()
248 $this->query("COMMIT");
252 /*=====================================================================*\
253 || ###################################################################
256 || ###################################################################
257 \*=====================================================================*/