In mail.php, we don't want to double encode fields so in send() create local variable...
[isso.git] / db_mysql.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright ©2002-[#]year[#] Blue Static
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 Blue Static
38 * @copyright Copyright ©2002 - [#]year[#], Blue Static
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 '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'
65 );
66
67 // ###################################################################
68 /**
69 * Constructor
70 */
71 function __construct(&$registry)
72 {
73 parent::__construct($registry);
74 }
75
76 // ###################################################################
77 /**
78 * (PHP 4) Constructor
79 */
80 function DB_MySQL(&$registry)
81 {
82 $this->__construct($registry);
83 }
84
85 // ###################################################################
86 /**
87 * Wrapper: mysql_pconnect
88 *
89 * @access protected
90 *
91 * @param string Server name
92 * @param string User name
93 * @param string Password
94 * @param string Database
95 *
96 * @return integer DB-Link
97 */
98 function command_mysql_pconnect($server, $user, $password, $database)
99 {
100 $link = mysql_pconnect($server, $user, $password);
101 $this->select_db($database, $link);
102
103 return $link;
104 }
105
106 // ###################################################################
107 /**
108 * Wrapper: mysql_connect
109 *
110 * @access protected
111 *
112 * @param string Server name
113 * @param string User name
114 * @param string Password
115 * @param string Database
116 *
117 * @return integer DB-Link
118 */
119 function command_mysql_connect($server, $user, $password, $database)
120 {
121 $link = mysql_connect($server, $user, $password, true);
122 $this->select_db($database, $link);
123
124 return $link;
125 }
126
127 // ###################################################################
128 /**
129 * Wrapper: mysql_select_db
130 *
131 * @access protected
132 *
133 * @param string Database name
134 * @param integer DB-Link
135 */
136 function select_db($database, $link)
137 {
138 if (!mysql_select_db($database, $link))
139 {
140 $this->error('Cannot use the database \'' . $database . '\'');
141 }
142 }
143
144 // ###################################################################
145 /**
146 * Wrapper: mysql_query
147 *
148 * @access protected
149 *
150 * @param integer DB-Link
151 * @param string Query string
152 *
153 * @return integer Result
154 */
155 function command_mysql_query($link, $string)
156 {
157 return mysql_query($string, $link);
158 }
159
160 // ###################################################################
161 /**
162 * Escapes a binary string for insertion into the database
163 *
164 * @access public
165 *
166 * @param string Unescaped data
167 *
168 * @return string Escaped binary data
169 */
170 function escape_binary($binary)
171 {
172 return mysql_escape_string($binary);
173 }
174
175 // ###################################################################
176 /**
177 * Wrapper: mysql(_real)_escape_string
178 *
179 * @access protected
180 *
181 * @param integer DB-Link
182 * @param string Unescaped text
183 *
184 * @return string Escaped text
185 */
186 function command_mysql_escape_string($link, $string)
187 {
188 if (function_exists('mysql_real_escape_string'))
189 {
190 return @mysql_real_escape_string($string, $link);
191 }
192 else
193 {
194 return @mysql_escape_string($string);
195 }
196 }
197
198 // ###################################################################
199 /**
200 * Not supported: unescape binary string
201 *
202 * @access protected
203 *
204 * @param string Escaped data
205 *
206 * @return string Same data
207 */
208 function command_unescape_binary($string)
209 {
210 return $string;
211 }
212
213 // ###################################################################
214 /**
215 * Starts a database transaction
216 *
217 * @access public
218 */
219 function transaction_start()
220 {
221 $this->query("BEGIN WORK");
222 }
223
224 // ###################################################################
225 /**
226 * Saves current transaction steps as a savepoint
227 *
228 * @access public
229 *
230 * @param string Named savepoint
231 */
232 function transaction_savepoint($name)
233 {
234 $this->query("SAVEPOINT $name");
235 }
236
237 // ###################################################################
238 /**
239 * Reverts a transaction back to a given savepoint
240 *
241 * @access public
242 *
243 * @param string Named savepoint
244 */
245 function transaction_rollback($name = null)
246 {
247 $this->query("ROLLBACK" . ($name != null ? " TO SAVEPOINT $name" : ""));
248 }
249
250 // ###################################################################
251 /**
252 * Commits a database transaction
253 *
254 * @access public
255 */
256 function transaction_commit()
257 {
258 $this->query("COMMIT");
259 }
260 }
261
262 /*=====================================================================*\
263 || ###################################################################
264 || # $HeadURL$
265 || # $Id$
266 || ###################################################################
267 \*=====================================================================*/
268 ?>