Removing the pconnect option from BSDb and it's children.
[isso.git] / DbMySql.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 Layer (DbMySql.php)
24 *
25 * @package ISSO
26 */
27
28 require_once('ISSO/Db.php');
29
30 /**
31 * MySQL Database Layer
32 *
33 * This framework is a function wrapper for MySQL functions so we can have
34 * better error reporting and query reporting.
35 *
36 * @author Blue Static
37 * @copyright Copyright ©2002 - [#]year[#], Blue Static
38 * @version $Revision$
39 * @package ISSO
40 *
41 */
42 class BSDbMySql extends BSDb
43 {
44 // ###################################################################
45 /**
46 * Wrapper: mysql_connect
47 */
48 protected function _connect($server, $user, $password, $database)
49 {
50 $link = @mysql_connect($server, $user, $password, true);
51 if ($link)
52 {
53 $this->_selectDb($database, $link);
54 }
55
56 return $link;
57 }
58
59 // ###################################################################
60 /**
61 * Opens a connection to the specified database name
62 *
63 * @param string Database name
64 * @param integer DB-Link
65 */
66 private function _selectDb($database, $link)
67 {
68 if (!mysql_select_db($database, $link))
69 {
70 $this->_error('Cannot use the database "' . $database . '"');
71 }
72 }
73
74 // ###################################################################
75 /**
76 * Wrapper: mysql_query
77 */
78 protected function _query($string)
79 {
80 return mysql_query($string, $this->dblink);
81 }
82
83 // ###################################################################
84 /**
85 * Wrapper: mysql_escape_string
86 */
87 protected function _escapeBinary($binary)
88 {
89 return mysql_escape_string($binary);
90 }
91
92 // ###################################################################
93 /**
94 * Wrapper: mysql(_real)_escape_string
95 */
96 protected function _escapeString($string)
97 {
98 if (function_exists('mysql_real_escape_string'))
99 {
100 return @mysql_real_escape_string($string, $this->dblink);
101 }
102 else
103 {
104 return @mysql_escape_string($string);
105 }
106 }
107
108 // ###################################################################
109 /**
110 * Not supported: unescape binary string
111 */
112 protected function _unescapeBinary($string)
113 {
114 return $string;
115 }
116
117 // ###################################################################
118 /**
119 * Wrapper: mysql_fetch_assoc
120 */
121 protected function _fetchAssocArray($result)
122 {
123 return mysql_fetch_assoc($result);
124 }
125
126 // ###################################################################
127 /**
128 * Wrapper: mysql_fetch_row
129 */
130 protected function _fetchRowArray($result)
131 {
132 return mysql_fetch_row($result);
133 }
134
135 // ###################################################################
136 /**
137 * Wrapper: mysql_fetch_object
138 */
139 public function _fetchObject($result)
140 {
141 return mysql_fetch_object($result);
142 }
143
144 // ###################################################################
145 /**
146 * Wrapper: mysql_free_result
147 */
148 protected function _freeResult($result)
149 {
150 mysql_free_result($result);
151 }
152
153 // ###################################################################
154 /**
155 * Wrapper: mysql_insert_id
156 */
157 protected function _insertId()
158 {
159 return mysql_insert_id($this->dblink);
160 }
161
162 // ###################################################################
163 /**
164 * Wrapper: mysql_num_rows
165 */
166 protected function _numRows($result)
167 {
168 return mysql_num_rows($result);
169 }
170
171 // ###################################################################
172 /**
173 * Wrapper: mysql_affected_rows
174 */
175 protected function _affectedRows($result)
176 {
177 return mysql_affected_rows($this->dblink);
178 }
179
180 // ###################################################################
181 /**
182 * Starts a database transaction
183 */
184 public function transactionStart()
185 {
186 $this->query("BEGIN WORK");
187 }
188
189 // ###################################################################
190 /**
191 * Saves current transaction steps as a savepoint
192 *
193 * @param string Named savepoint
194 */
195 public function transactionSavepoint($name)
196 {
197 $this->query("SAVEPOINT $name");
198 }
199
200 // ###################################################################
201 /**
202 * Reverts a transaction back to a given savepoint
203 *
204 * @param string Named savepoint
205 */
206 public function transactionRollback($name = null)
207 {
208 $this->query("ROLLBACK" . ($name != null ? " TO SAVEPOINT $name" : ""));
209 }
210
211 // ###################################################################
212 /**
213 * Commits a database transaction
214 */
215 public function transactionCommit()
216 {
217 $this->query("COMMIT");
218 }
219
220 // ###################################################################
221 /**
222 * Returns the error number
223 *
224 * @return integer Error number
225 */
226 public function _errorNumber()
227 {
228 return mysql_errno($this->dblink);
229 }
230
231 // ###################################################################
232 /**
233 * Returns the error string
234 *
235 * @return string Error string
236 */
237 public function _errorString()
238 {
239 return mysql_error($this->dblink);
240 }
241 }
242
243 /*=====================================================================*\
244 || ###################################################################
245 || # $HeadURL$
246 || # $Id$
247 || ###################################################################
248 \*=====================================================================*/
249 ?>