]> src.bluestatic.org Git - isso.git/blob - DbMySql.php
Update version number
[isso.git] / DbMySql.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 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 2 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 (c)2005 - 2008, Blue Static
38 * @package ISSO
39 *
40 */
41 class BSDbMySql extends BSDb
42 {
43 /**
44 * Wrapper: mysql_connect
45 */
46 protected function _connect($server, $user, $password, $database)
47 {
48 $link = @mysql_connect($server, $user, $password, true);
49 if ($link)
50 {
51 $this->_selectDb($database, $link);
52 }
53
54 return $link;
55 }
56
57 /**
58 * Opens a connection to the specified database name
59 *
60 * @param string Database name
61 * @param integer DB-Link
62 */
63 private function _selectDb($database, $link)
64 {
65 if (!mysql_select_db($database, $link))
66 {
67 throw new BSDbException($this->_errorString(), $this->_errorNumber(), 'Cannot use the database ' . $database);
68 }
69 }
70
71 /**
72 * Wrapper: mysql_query
73 */
74 protected function _query($string)
75 {
76 return mysql_query($string, $this->dblink);
77 }
78
79 /**
80 * Wrapper: mysql_escape_string
81 */
82 protected function _escapeBinary($binary)
83 {
84 return mysql_escape_string($binary);
85 }
86
87 /**
88 * Wrapper: mysql(_real)_escape_string
89 */
90 protected function _escapeString($string)
91 {
92 if (function_exists('mysql_real_escape_string'))
93 {
94 return @mysql_real_escape_string($string, $this->dblink);
95 }
96 else
97 {
98 return @mysql_escape_string($string);
99 }
100 }
101
102 /**
103 * Not supported: unescape binary string
104 */
105 protected function _unescapeBinary($string)
106 {
107 return $string;
108 }
109
110 /**
111 * Wrapper: mysql_insert_id
112 */
113 protected function _insertId()
114 {
115 return mysql_insert_id($this->dblink);
116 }
117
118 /**
119 * Wrapper: mysql_affected_rows
120 */
121 protected function _affectedRows($result)
122 {
123 return mysql_affected_rows($this->dblink);
124 }
125
126 /**
127 * Starts a database transaction
128 */
129 public function begin()
130 {
131 $this->query("BEGIN WORK");
132 }
133
134 /**
135 * Reverts a transaction back to a given savepoint
136 */
137 public function rollback()
138 {
139 $this->query("ROLLBACK");
140 }
141
142 /**
143 * Commits a database transaction
144 */
145 public function commit()
146 {
147 $this->query("COMMIT");
148 }
149
150 /**
151 * Returns the error number
152 *
153 * @return integer Error number
154 */
155 public function _errorNumber()
156 {
157 return mysql_errno($this->dblink);
158 }
159
160 /**
161 * Returns the error string
162 *
163 * @return string Error string
164 */
165 public function _errorString()
166 {
167 return mysql_error($this->dblink);
168 }
169 }
170
171 /**
172 * Database Result
173 *
174 * This class holds result information for a database result
175 *
176 * @author rsesek
177 * @copyright Copyright (c)2005 - 2008, Blue Static
178 * @package ISSO
179 *
180 */
181 class BSDbMySqlResult extends BSDbResult
182 {
183 /**
184 * Wrapper: mysql_fetch_assoc
185 */
186 protected function _fetchAssocArray($result)
187 {
188 return mysql_fetch_assoc($result);
189 }
190
191 /**
192 * Wrapper: mysql_fetch_row
193 */
194 protected function _fetchRowArray($result)
195 {
196 return mysql_fetch_row($result);
197 }
198
199 /**
200 * Wrapper: mysql_fetch_object
201 */
202 public function _fetchObject($result)
203 {
204 return mysql_fetch_object($result);
205 }
206
207 /**
208 * Wrapper: mysql_free_result
209 */
210 protected function _freeResult($result)
211 {
212 mysql_free_result($result);
213 }
214
215 /**
216 * Wrapper: mysql_num_rows
217 */
218 protected function _numRows($result)
219 {
220 return mysql_num_rows($result);
221 }
222 }
223
224 ?>