Run the generate_footer_html() function
[isso.git] / db_mysql.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 /**
23 * MySQL Database Abstraction Layer
24 * db_mysql.php
25 *
26 * @package ISSO
27 */
28
29 $this->load('db', null);
30
31 /**
32 * MySQL Database Abstraction Layer
33 *
34 * This framework is a function wrapper for MySQL functions so we can have
35 * better error reporting and query reporting.
36 *
37 * @author Iris Studios, Inc.
38 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
39 * @version $Revision$
40 * @package ISSO
41 *
42 */
43 class DB_MySQL extends DB_Abstract
44 {
45 /**
46 * Command mapping list
47 * @var array
48 * @access private
49 */
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 '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'
64 );
65
66 // ###################################################################
67 /**
68 * Constructor
69 */
70 function __construct(&$registry)
71 {
72 parent::__construct($registry);
73 }
74
75 // ###################################################################
76 /**
77 * (PHP 4) Constructor
78 */
79 function DB_MySQL(&$registry)
80 {
81 $this->__construct($registry);
82 }
83
84 // ###################################################################
85 /**
86 * Wrapper: mysql_pconnect
87 *
88 * @access protected
89 *
90 * @param string Server name
91 * @param string User name
92 * @param string Password
93 * @param string Database
94 *
95 * @return integer DB-Link
96 */
97 function command_mysql_pconnect($server, $user, $password, $database)
98 {
99 $link = mysql_pconnect($server, $user, $password);
100 $this->select_db($database, $link);
101
102 return $link;
103 }
104
105 // ###################################################################
106 /**
107 * Wrapper: mysql_connect
108 *
109 * @access protected
110 *
111 * @param string Server name
112 * @param string User name
113 * @param string Password
114 * @param string Database
115 *
116 * @return integer DB-Link
117 */
118 function command_mysql_connect($server, $user, $password, $database)
119 {
120 $link = mysql_connect($server, $user, $password);
121 $this->select_db($database, $link);
122
123 return $link;
124 }
125
126 // ###################################################################
127 /**
128 * Wrapper: mysql_select_db
129 *
130 * @access protected
131 *
132 * @param string Database name
133 * @param integer DB-Link
134 */
135 function select_db($database, $link)
136 {
137 if (!mysql_select_db($database, $link))
138 {
139 $this->error('Cannot use the database \'' . $this->database . '\'');
140 }
141 }
142
143 // ###################################################################
144 /**
145 * Wrapper: mysql_query
146 *
147 * @access protected
148 *
149 * @param integer DB-Link
150 * @param string Query string
151 *
152 * @return integer Result
153 */
154 function command_mysql_query($link, $string)
155 {
156 return mysql_query($string, $link);
157 }
158
159 // ###################################################################
160 /**
161 * Wrapper: mysql(_real)_escape_string
162 *
163 * @access protected
164 *
165 * @param integer DB-Link
166 * @param string Unescaped text
167 *
168 * @return string Escaped text
169 */
170 function command_mysql_escape_string($link, $string)
171 {
172 if (function_exists('mysql_real_escape_string'))
173 {
174 return mysql_real_escape_string($string, $link);
175 }
176 else
177 {
178 return mysql_escape_string($string);
179 }
180 }
181
182 // ###################################################################
183 /**
184 * Not supported: unescape binary string
185 *
186 * @access protected
187 *
188 * @param string Escaped data
189 *
190 * @return string Same data
191 */
192 function command_unescape_binary($string)
193 {
194 return $string;
195 }
196
197 // ###################################################################
198 /**
199 * Starts a database transaction
200 *
201 * @access public
202 */
203 function transaction_start()
204 {
205 $this->query("BEGIN WORK");
206 }
207
208 // ###################################################################
209 /**
210 * Saves current transaction steps as a savepoint
211 *
212 * @access public
213 *
214 * @param string Named savepoint
215 */
216 function transaction_savepoint($name)
217 {
218 $this->query("SAVEPOINT $name");
219 }
220
221 // ###################################################################
222 /**
223 * Reverts a transaction back to a given savepoint
224 *
225 * @access public
226 *
227 * @param string Named savepoint
228 */
229 function transaction_rollback($name = null)
230 {
231 $this->query("ROLLBACK" . ($name != null ? " TO SAVEPOINT $name" : ""));
232 }
233
234 // ###################################################################
235 /**
236 * Commits a database transaction
237 *
238 * @access public
239 */
240 function transaction_commit()
241 {
242 $this->query("COMMIT");
243 }
244 }
245
246 /*=====================================================================*\
247 || ###################################################################
248 || # $HeadURL$
249 || # $Id$
250 || ###################################################################
251 \*=====================================================================*/
252 ?>