Rename some terminology
[isso.git] / db_mysql.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]version[#]
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 */
49 var $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 'fetch_assoc' => 'mysql_fetch_assoc',
57 'fetch_object' => 'mysql_fetch_object',
58 'free_result' => 'mysql_free_result',
59 'insert_id' => 'mysql_insert_id',
60 'num_rows' => 'mysql_num_rows',
61 'affected_rows' => 'mysql_affected_rows'
62 );
63
64 // ###################################################################
65 /**
66 * Constructor
67 */
68 function __construct(&$registry)
69 {
70 parent::__construct($registry);
71 }
72
73 // ###################################################################
74 /**
75 * (PHP 4) Constructor
76 */
77 function DB_MySQL(&$registry)
78 {
79 $this->__construct($registry);
80 }
81
82 // ###################################################################
83 /**
84 * Wrapper: mysql_pconnect
85 *
86 * @access protected
87 *
88 * @param string Server name
89 * @param string User name
90 * @param string Password
91 * @param string Database
92 *
93 * @return integer DB-Link
94 */
95 function command_mysql_pconnect($server, $user, $password, $database)
96 {
97 $link = mysql_pconnect($server, $user, $password);
98 $this->select_db($database, $link);
99
100 return $link;
101 }
102
103 // ###################################################################
104 /**
105 * Wrapper: mysql_connect
106 *
107 * @access protected
108 *
109 * @param string Server name
110 * @param string User name
111 * @param string Password
112 * @param string Database
113 *
114 * @return integer DB-Link
115 */
116 function command_mysql_connect($server, $user, $password, $database)
117 {
118 $link = mysql_connect($server, $user, $password);
119 $this->select_db($database, $link);
120
121 return $link;
122 }
123
124 // ###################################################################
125 /**
126 * Wrapper: mysql_select_db
127 *
128 * @access protected
129 *
130 * @param string Database name
131 * @param integer DB-Link
132 */
133 function select_db($database, $link)
134 {
135 if (!mysql_select_db($database, $link))
136 {
137 $this->error('Cannot use the database \'' . $this->database . '\'');
138 }
139 }
140
141 // ###################################################################
142 /**
143 * Wrapper: mysql_query
144 *
145 * @access protected
146 *
147 * @param integer DB-Link
148 * @param string Query string
149 *
150 * @return integer Result
151 */
152 function command_mysql_query($link, $string)
153 {
154 return mysql_query($string, $link);
155 }
156
157 // ###################################################################
158 /**
159 * Wrapper: mysql(_real)_escape_string
160 *
161 * @access protected
162 *
163 * @param integer DB-Link
164 * @param string Unescaped text
165 *
166 * @return string Escaped text
167 */
168 function command_mysql_escape_string($link, $string)
169 {
170 if (function_exists('mysql_real_escape_string'))
171 {
172 return mysql_real_escape_string($string, $link);
173 }
174 else
175 {
176 return mysql_escape_string($string);
177 }
178 }
179 }
180
181 /*=====================================================================*\
182 || ###################################################################
183 || # $HeadURL$
184 || # $Id$
185 || ###################################################################
186 \*=====================================================================*/
187 ?>