Редакция 2 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 2 | Редакция 3 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | 2 | ||
3 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
4 | 4 | ||
5 | /**
|
5 | /**
|
6 | * The PEAR DB driver for PHP's mysql extension
|
6 | * The PEAR DB driver for PHP's mysql extension
|
7 | * for interacting with MySQL databases
|
7 | * for interacting with MySQL databases
|
8 | *
|
8 | *
|
9 | * PHP versions 4 and 5
|
9 | * PHP versions 4 and 5
|
10 | *
|
10 | *
|
11 | * LICENSE: This source file is subject to version 3.0 of the PHP license
|
11 | * LICENSE: This source file is subject to version 3.0 of the PHP license
|
12 | * that is available through the world-wide-web at the following URI:
|
12 | * that is available through the world-wide-web at the following URI:
|
13 | * http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
13 | * http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
14 | * the PHP License and are unable to obtain it through the web, please
|
14 | * the PHP License and are unable to obtain it through the web, please
|
15 | * send a note to license@php.net so we can mail you a copy immediately.
|
15 | * send a note to license@php.net so we can mail you a copy immediately.
|
16 | *
|
16 | *
|
17 | * @category Database
|
17 | * @category Database
|
18 | * @package DB
|
18 | * @package DB
|
19 | * @author Stig Bakken <ssb@php.net>
|
19 | * @author Stig Bakken <ssb@php.net>
|
20 | * @author Daniel Convissor <danielc@php.net>
|
20 | * @author Daniel Convissor <danielc@php.net>
|
21 | * @copyright 1997-2007 The PHP Group
|
21 | * @copyright 1997-2007 The PHP Group
|
22 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
22 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
23 | * @version CVS: $Id: mysql.php,v 1.126 2007/09/21 13:32:52 aharvey Exp $
|
23 | * @version CVS: $Id: mysql.php,v 1.126 2007/09/21 13:32:52 aharvey Exp $
|
24 | * @link http://pear.php.net/package/DB
|
24 | * @link http://pear.php.net/package/DB
|
25 | */
|
25 | */
|
26 | 26 | ||
27 | /**
|
27 | /**
|
28 | * Obtain the DB_common class so it can be extended from
|
28 | * Obtain the DB_common class so it can be extended from
|
29 | */
|
29 | */
|
30 | require_once 'DB/common.php'; |
30 | require_once 'DB/common.php'; |
31 | 31 | ||
32 | /**
|
32 | /**
|
33 | * The methods PEAR DB uses to interact with PHP's mysql extension
|
33 | * The methods PEAR DB uses to interact with PHP's mysql extension
|
34 | * for interacting with MySQL databases
|
34 | * for interacting with MySQL databases
|
35 | *
|
35 | *
|
36 | * These methods overload the ones declared in DB_common.
|
36 | * These methods overload the ones declared in DB_common.
|
37 | *
|
37 | *
|
38 | * @category Database
|
38 | * @category Database
|
39 | * @package DB
|
39 | * @package DB
|
40 | * @author Stig Bakken <ssb@php.net>
|
40 | * @author Stig Bakken <ssb@php.net>
|
41 | * @author Daniel Convissor <danielc@php.net>
|
41 | * @author Daniel Convissor <danielc@php.net>
|
42 | * @copyright 1997-2007 The PHP Group
|
42 | * @copyright 1997-2007 The PHP Group
|
43 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
43 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
44 | * @version Release: 1.7.13
|
44 | * @version Release: 1.7.13
|
45 | * @link http://pear.php.net/package/DB
|
45 | * @link http://pear.php.net/package/DB
|
46 | */
|
46 | */
|
47 | class DB_mysql extends DB_common |
47 | class DB_mysql extends DB_common |
48 | {
|
48 | {
|
49 | // {{{ properties
|
49 | // {{{ properties
|
50 | 50 | ||
51 | /**
|
51 | /**
|
52 | * The DB driver type (mysql, oci8, odbc, etc.)
|
52 | * The DB driver type (mysql, oci8, odbc, etc.)
|
53 | * @var string
|
53 | * @var string
|
54 | */
|
54 | */
|
55 | var $phptype = 'mysql'; |
55 | var $phptype = 'mysql'; |
56 | 56 | ||
57 | /**
|
57 | /**
|
58 | * The database syntax variant to be used (db2, access, etc.), if any
|
58 | * The database syntax variant to be used (db2, access, etc.), if any
|
59 | * @var string
|
59 | * @var string
|
60 | */
|
60 | */
|
61 | var $dbsyntax = 'mysql'; |
61 | var $dbsyntax = 'mysql'; |
62 | 62 | ||
63 | /**
|
63 | /**
|
64 | * The capabilities of this DB implementation
|
64 | * The capabilities of this DB implementation
|
65 | *
|
65 | *
|
66 | * The 'new_link' element contains the PHP version that first provided
|
66 | * The 'new_link' element contains the PHP version that first provided
|
67 | * new_link support for this DBMS. Contains false if it's unsupported.
|
67 | * new_link support for this DBMS. Contains false if it's unsupported.
|
68 | *
|
68 | *
|
69 | * Meaning of the 'limit' element:
|
69 | * Meaning of the 'limit' element:
|
70 | * + 'emulate' = emulate with fetch row by number
|
70 | * + 'emulate' = emulate with fetch row by number
|
71 | * + 'alter' = alter the query
|
71 | * + 'alter' = alter the query
|
72 | * + false = skip rows
|
72 | * + false = skip rows
|
73 | *
|
73 | *
|
74 | * @var array
|
74 | * @var array
|
75 | */
|
75 | */
|
76 | var $features = array( |
76 | var $features = array( |
77 | 'limit' => 'alter', |
77 | 'limit' => 'alter', |
78 | 'new_link' => '4.2.0', |
78 | 'new_link' => '4.2.0', |
79 | 'numrows' => true, |
79 | 'numrows' => true, |
80 | 'pconnect' => true, |
80 | 'pconnect' => true, |
81 | 'prepare' => false, |
81 | 'prepare' => false, |
82 | 'ssl' => false, |
82 | 'ssl' => false, |
83 | 'transactions' => true, |
83 | 'transactions' => true, |
84 | ); |
84 | ); |
85 | 85 | ||
86 | /**
|
86 | /**
|
87 | * A mapping of native error codes to DB error codes
|
87 | * A mapping of native error codes to DB error codes
|
88 | * @var array
|
88 | * @var array
|
89 | */
|
89 | */
|
90 | var $errorcode_map = array( |
90 | var $errorcode_map = array( |
91 | 1004 => DB_ERROR_CANNOT_CREATE, |
91 | 1004 => DB_ERROR_CANNOT_CREATE, |
92 | 1005 => DB_ERROR_CANNOT_CREATE, |
92 | 1005 => DB_ERROR_CANNOT_CREATE, |
93 | 1006 => DB_ERROR_CANNOT_CREATE, |
93 | 1006 => DB_ERROR_CANNOT_CREATE, |
94 | 1007 => DB_ERROR_ALREADY_EXISTS, |
94 | 1007 => DB_ERROR_ALREADY_EXISTS, |
95 | 1008 => DB_ERROR_CANNOT_DROP, |
95 | 1008 => DB_ERROR_CANNOT_DROP, |
96 | 1022 => DB_ERROR_ALREADY_EXISTS, |
96 | 1022 => DB_ERROR_ALREADY_EXISTS, |
97 | 1044 => DB_ERROR_ACCESS_VIOLATION, |
97 | 1044 => DB_ERROR_ACCESS_VIOLATION, |
98 | 1046 => DB_ERROR_NODBSELECTED, |
98 | 1046 => DB_ERROR_NODBSELECTED, |
99 | 1048 => DB_ERROR_CONSTRAINT, |
99 | 1048 => DB_ERROR_CONSTRAINT, |
100 | 1049 => DB_ERROR_NOSUCHDB, |
100 | 1049 => DB_ERROR_NOSUCHDB, |
101 | 1050 => DB_ERROR_ALREADY_EXISTS, |
101 | 1050 => DB_ERROR_ALREADY_EXISTS, |
102 | 1051 => DB_ERROR_NOSUCHTABLE, |
102 | 1051 => DB_ERROR_NOSUCHTABLE, |
103 | 1054 => DB_ERROR_NOSUCHFIELD, |
103 | 1054 => DB_ERROR_NOSUCHFIELD, |
104 | 1061 => DB_ERROR_ALREADY_EXISTS, |
104 | 1061 => DB_ERROR_ALREADY_EXISTS, |
105 | 1062 => DB_ERROR_ALREADY_EXISTS, |
105 | 1062 => DB_ERROR_ALREADY_EXISTS, |
106 | 1064 => DB_ERROR_SYNTAX, |
106 | 1064 => DB_ERROR_SYNTAX, |
107 | 1091 => DB_ERROR_NOT_FOUND, |
107 | 1091 => DB_ERROR_NOT_FOUND, |
108 | 1100 => DB_ERROR_NOT_LOCKED, |
108 | 1100 => DB_ERROR_NOT_LOCKED, |
109 | 1136 => DB_ERROR_VALUE_COUNT_ON_ROW, |
109 | 1136 => DB_ERROR_VALUE_COUNT_ON_ROW, |
110 | 1142 => DB_ERROR_ACCESS_VIOLATION, |
110 | 1142 => DB_ERROR_ACCESS_VIOLATION, |
111 | 1146 => DB_ERROR_NOSUCHTABLE, |
111 | 1146 => DB_ERROR_NOSUCHTABLE, |
112 | 1216 => DB_ERROR_CONSTRAINT, |
112 | 1216 => DB_ERROR_CONSTRAINT, |
113 | 1217 => DB_ERROR_CONSTRAINT, |
113 | 1217 => DB_ERROR_CONSTRAINT, |
114 | 1356 => DB_ERROR_DIVZERO, |
114 | 1356 => DB_ERROR_DIVZERO, |
115 | 1451 => DB_ERROR_CONSTRAINT, |
115 | 1451 => DB_ERROR_CONSTRAINT, |
116 | 1452 => DB_ERROR_CONSTRAINT, |
116 | 1452 => DB_ERROR_CONSTRAINT, |
117 | ); |
117 | ); |
118 | 118 | ||
119 | /**
|
119 | /**
|
120 | * The raw database connection created by PHP
|
120 | * The raw database connection created by PHP
|
121 | * @var resource
|
121 | * @var resource
|
122 | */
|
122 | */
|
123 | var $connection; |
123 | var $connection; |
124 | 124 | ||
125 | /**
|
125 | /**
|
126 | * The DSN information for connecting to a database
|
126 | * The DSN information for connecting to a database
|
127 | * @var array
|
127 | * @var array
|
128 | */
|
128 | */
|
129 | var $dsn = array(); |
129 | var $dsn = array(); |
130 | 130 | ||
131 | 131 | ||
132 | /**
|
132 | /**
|
133 | * Should data manipulation queries be committed automatically?
|
133 | * Should data manipulation queries be committed automatically?
|
134 | * @var bool
|
134 | * @var bool
|
135 | * @access private
|
135 | * @access private
|
136 | */
|
136 | */
|
137 | var $autocommit = true; |
137 | var $autocommit = true; |
138 | 138 | ||
139 | /**
|
139 | /**
|
140 | * The quantity of transactions begun
|
140 | * The quantity of transactions begun
|
141 | *
|
141 | *
|
142 | * {@internal While this is private, it can't actually be designated
|
142 | * {@internal While this is private, it can't actually be designated
|
143 | * private in PHP 5 because it is directly accessed in the test suite.}}
|
143 | * private in PHP 5 because it is directly accessed in the test suite.}}
|
144 | *
|
144 | *
|
145 | * @var integer
|
145 | * @var integer
|
146 | * @access private
|
146 | * @access private
|
147 | */
|
147 | */
|
148 | var $transaction_opcount = 0; |
148 | var $transaction_opcount = 0; |
149 | 149 | ||
150 | /**
|
150 | /**
|
151 | * The database specified in the DSN
|
151 | * The database specified in the DSN
|
152 | *
|
152 | *
|
153 | * It's a fix to allow calls to different databases in the same script.
|
153 | * It's a fix to allow calls to different databases in the same script.
|
154 | *
|
154 | *
|
155 | * @var string
|
155 | * @var string
|
156 | * @access private
|
156 | * @access private
|
157 | */
|
157 | */
|
158 | var $_db = ''; |
158 | var $_db = ''; |
159 | 159 | ||
160 | 160 | ||
161 | // }}}
|
161 | // }}}
|
162 | // {{{ constructor
|
162 | // {{{ constructor
|
163 | 163 | ||
164 | /**
|
164 | /**
|
165 | * This constructor calls <kbd>$this->DB_common()</kbd>
|
165 | * This constructor calls <kbd>$this->DB_common()</kbd>
|
166 | *
|
166 | *
|
167 | * @return void
|
167 | * @return void
|
168 | */
|
168 | */
|
169 | function DB_mysql() |
169 | function DB_mysql() |
170 | {
|
170 | {
|
171 | $this->DB_common(); |
171 | $this->DB_common(); |
172 | }
|
172 | }
|
173 | 173 | ||
174 | // }}}
|
174 | // }}}
|
175 | // {{{ connect()
|
175 | // {{{ connect()
|
176 | 176 | ||
177 | /**
|
177 | /**
|
178 | * Connect to the database server, log in and open the database
|
178 | * Connect to the database server, log in and open the database
|
179 | *
|
179 | *
|
180 | * Don't call this method directly. Use DB::connect() instead.
|
180 | * Don't call this method directly. Use DB::connect() instead.
|
181 | *
|
181 | *
|
182 | * PEAR DB's mysql driver supports the following extra DSN options:
|
182 | * PEAR DB's mysql driver supports the following extra DSN options:
|
183 | * + new_link If set to true, causes subsequent calls to connect()
|
183 | * + new_link If set to true, causes subsequent calls to connect()
|
184 | * to return a new connection link instead of the
|
184 | * to return a new connection link instead of the
|
185 | * existing one. WARNING: this is not portable to
|
185 | * existing one. WARNING: this is not portable to
|
186 | * other DBMS's. Available since PEAR DB 1.7.0.
|
186 | * other DBMS's. Available since PEAR DB 1.7.0.
|
187 | * + client_flags Any combination of MYSQL_CLIENT_* constants.
|
187 | * + client_flags Any combination of MYSQL_CLIENT_* constants.
|
188 | * Only used if PHP is at version 4.3.0 or greater.
|
188 | * Only used if PHP is at version 4.3.0 or greater.
|
189 | * Available since PEAR DB 1.7.0.
|
189 | * Available since PEAR DB 1.7.0.
|
190 | *
|
190 | *
|
191 | * @param array $dsn the data source name
|
191 | * @param array $dsn the data source name
|
192 | * @param bool $persistent should the connection be persistent?
|
192 | * @param bool $persistent should the connection be persistent?
|
193 | *
|
193 | *
|
194 | * @return int DB_OK on success. A DB_Error object on failure.
|
194 | * @return int DB_OK on success. A DB_Error object on failure.
|
195 | */
|
195 | */
|
196 | function connect($dsn, $persistent = false) |
196 | function connect($dsn, $persistent = false) |
197 | {
|
197 | {
|
198 | if (!PEAR::loadExtension('mysql')) { |
198 | if (!PEAR::loadExtension('mysql')) { |
199 | return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); |
199 | return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); |
200 | }
|
200 | }
|
201 | 201 | ||
202 | $this->dsn = $dsn; |
202 | $this->dsn = $dsn; |
203 | if ($dsn['dbsyntax']) { |
203 | if ($dsn['dbsyntax']) { |
204 | $this->dbsyntax = $dsn['dbsyntax']; |
204 | $this->dbsyntax = $dsn['dbsyntax']; |
205 | }
|
205 | }
|
206 | 206 | ||
207 | $params = array(); |
207 | $params = array(); |
208 | if ($dsn['protocol'] && $dsn['protocol'] == 'unix') { |
208 | if ($dsn['protocol'] && $dsn['protocol'] == 'unix') { |
209 | $params[0] = ':' . $dsn['socket']; |
209 | $params[0] = ':' . $dsn['socket']; |
210 | } else { |
210 | } else { |
211 | $params[0] = $dsn['hostspec'] ? $dsn['hostspec'] |
211 | $params[0] = $dsn['hostspec'] ? $dsn['hostspec'] |
212 | : 'localhost'; |
212 | : 'localhost'; |
213 | if ($dsn['port']) { |
213 | if ($dsn['port']) { |
214 | $params[0] .= ':' . $dsn['port']; |
214 | $params[0] .= ':' . $dsn['port']; |
215 | }
|
215 | }
|
216 | }
|
216 | }
|
217 | $params[] = $dsn['username'] ? $dsn['username'] : null; |
217 | $params[] = $dsn['username'] ? $dsn['username'] : null; |
218 | $params[] = $dsn['password'] ? $dsn['password'] : null; |
218 | $params[] = $dsn['password'] ? $dsn['password'] : null; |
219 | 219 | ||
220 | if (!$persistent) { |
220 | if (!$persistent) { |
221 | if (isset($dsn['new_link']) |
221 | if (isset($dsn['new_link']) |
222 | && ($dsn['new_link'] == 'true' || $dsn['new_link'] === true)) |
222 | && ($dsn['new_link'] == 'true' || $dsn['new_link'] === true)) |
223 | {
|
223 | {
|
224 | $params[] = true; |
224 | $params[] = true; |
225 | } else { |
225 | } else { |
226 | $params[] = false; |
226 | $params[] = false; |
227 | }
|
227 | }
|
228 | }
|
228 | }
|
229 | if (version_compare(phpversion(), '4.3.0', '>=')) { |
229 | if (version_compare(phpversion(), '4.3.0', '>=')) { |
230 | $params[] = isset($dsn['client_flags']) |
230 | $params[] = isset($dsn['client_flags']) |
231 | ? $dsn['client_flags'] : null; |
231 | ? $dsn['client_flags'] : null; |
232 | }
|
232 | }
|
233 | 233 | ||
234 | $connect_function = $persistent ? 'mysql_pconnect' : 'mysql_connect'; |
234 | $connect_function = $persistent ? 'mysql_pconnect' : 'mysql_connect'; |
235 | 235 | ||
236 | $ini = ini_get('track_errors'); |
236 | $ini = ini_get('track_errors'); |
237 | $php_errormsg = ''; |
237 | $php_errormsg = ''; |
238 | if ($ini) { |
238 | if ($ini) { |
239 | $this->connection = @call_user_func_array($connect_function, |
239 | $this->connection = @call_user_func_array($connect_function, |
240 | $params); |
240 | $params); |
241 | } else { |
241 | } else { |
242 | @ini_set('track_errors', 1); |
242 | @ini_set('track_errors', 1); |
243 | $this->connection = @call_user_func_array($connect_function, |
243 | $this->connection = @call_user_func_array($connect_function, |
244 | $params); |
244 | $params); |
245 | @ini_set('track_errors', $ini); |
245 | @ini_set('track_errors', $ini); |
246 | }
|
246 | }
|
247 | 247 | ||
248 | if (!$this->connection) { |
248 | if (!$this->connection) { |
249 | if (($err = @mysql_error()) != '') { |
249 | if (($err = @mysql_error()) != '') { |
250 | return $this->raiseError(DB_ERROR_CONNECT_FAILED, |
250 | return $this->raiseError(DB_ERROR_CONNECT_FAILED, |
251 | null, null, null, |
251 | null, null, null, |
252 | $err); |
252 | $err); |
253 | } else { |
253 | } else { |
254 | return $this->raiseError(DB_ERROR_CONNECT_FAILED, |
254 | return $this->raiseError(DB_ERROR_CONNECT_FAILED, |
255 | null, null, null, |
255 | null, null, null, |
256 | $php_errormsg); |
256 | $php_errormsg); |
257 | }
|
257 | }
|
258 | }
|
258 | }
|
259 | 259 | ||
260 | if ($dsn['database']) { |
260 | if ($dsn['database']) { |
261 | if (!@mysql_select_db($dsn['database'], $this->connection)) { |
261 | if (!@mysql_select_db($dsn['database'], $this->connection)) { |
262 | return $this->mysqlRaiseError(); |
262 | return $this->mysqlRaiseError(); |
263 | }
|
263 | }
|
264 | $this->_db = $dsn['database']; |
264 | $this->_db = $dsn['database']; |
265 | }
|
265 | }
|
266 | 266 | ||
267 | return DB_OK; |
267 | return DB_OK; |
268 | }
|
268 | }
|
269 | 269 | ||
270 | // }}}
|
270 | // }}}
|
271 | // {{{ disconnect()
|
271 | // {{{ disconnect()
|
272 | 272 | ||
273 | /**
|
273 | /**
|
274 | * Disconnects from the database server
|
274 | * Disconnects from the database server
|
275 | *
|
275 | *
|
276 | * @return bool TRUE on success, FALSE on failure
|
276 | * @return bool TRUE on success, FALSE on failure
|
277 | */
|
277 | */
|
278 | function disconnect() |
278 | function disconnect() |
279 | {
|
279 | {
|
280 | $ret = @mysql_close($this->connection); |
280 | $ret = @mysql_close($this->connection); |
281 | $this->connection = null; |
281 | $this->connection = null; |
282 | return $ret; |
282 | return $ret; |
283 | }
|
283 | }
|
284 | 284 | ||
285 | // }}}
|
285 | // }}}
|
286 | // {{{ simpleQuery()
|
286 | // {{{ simpleQuery()
|
287 | 287 | ||
288 | /**
|
288 | /**
|
289 | * Sends a query to the database server
|
289 | * Sends a query to the database server
|
290 | *
|
290 | *
|
291 | * Generally uses mysql_query(). If you want to use
|
291 | * Generally uses mysql_query(). If you want to use
|
292 | * mysql_unbuffered_query() set the "result_buffering" option to 0 using
|
292 | * mysql_unbuffered_query() set the "result_buffering" option to 0 using
|
293 | * setOptions(). This option was added in Release 1.7.0.
|
293 | * setOptions(). This option was added in Release 1.7.0.
|
294 | *
|
294 | *
|
295 | * @param string the SQL query string
|
295 | * @param string the SQL query string
|
296 | *
|
296 | *
|
297 | * @return mixed + a PHP result resrouce for successful SELECT queries
|
297 | * @return mixed + a PHP result resrouce for successful SELECT queries
|
298 | * + the DB_OK constant for other successful queries
|
298 | * + the DB_OK constant for other successful queries
|
299 | * + a DB_Error object on failure
|
299 | * + a DB_Error object on failure
|
300 | */
|
300 | */
|
301 | function simpleQuery($query) |
301 | function simpleQuery($query) |
302 | {
|
302 | {
|
303 | $ismanip = $this->_checkManip($query); |
303 | $ismanip = $this->_checkManip($query); |
304 | $this->last_query = $query; |
304 | $this->last_query = $query; |
305 | $query = $this->modifyQuery($query); |
305 | $query = $this->modifyQuery($query); |
306 | if ($this->_db) { |
306 | if ($this->_db) { |
307 | if (!@mysql_select_db($this->_db, $this->connection)) { |
307 | if (!@mysql_select_db($this->_db, $this->connection)) { |
308 | return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); |
308 | return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); |
309 | }
|
309 | }
|
310 | }
|
310 | }
|
311 | if (!$this->autocommit && $ismanip) { |
311 | if (!$this->autocommit && $ismanip) { |
312 | if ($this->transaction_opcount == 0) { |
312 | if ($this->transaction_opcount == 0) { |
313 | $result = @mysql_query('SET AUTOCOMMIT=0', $this->connection); |
313 | $result = @mysql_query('SET AUTOCOMMIT=0', $this->connection); |
314 | $result = @mysql_query('BEGIN', $this->connection); |
314 | $result = @mysql_query('BEGIN', $this->connection); |
315 | if (!$result) { |
315 | if (!$result) { |
316 | return $this->mysqlRaiseError(); |
316 | return $this->mysqlRaiseError(); |
317 | }
|
317 | }
|
318 | }
|
318 | }
|
319 | $this->transaction_opcount++; |
319 | $this->transaction_opcount++; |
320 | }
|
320 | }
|
321 | if (!$this->options['result_buffering']) { |
321 | if (!$this->options['result_buffering']) { |
322 | $result = @mysql_unbuffered_query($query, $this->connection); |
322 | $result = @mysql_unbuffered_query($query, $this->connection); |
323 | } else { |
323 | } else { |
324 | $result = @mysql_query($query, $this->connection); |
324 | $result = @mysql_query($query, $this->connection); |
325 | }
|
325 | }
|
326 | if (!$result) { |
326 | if (!$result) { |
327 | return $this->mysqlRaiseError(); |
327 | return $this->mysqlRaiseError(); |
328 | }
|
328 | }
|
329 | if (is_resource($result)) { |
329 | if (is_resource($result)) { |
330 | return $result; |
330 | return $result; |
331 | }
|
331 | }
|
332 | return DB_OK; |
332 | return DB_OK; |
333 | }
|
333 | }
|
334 | 334 | ||
335 | // }}}
|
335 | // }}}
|
336 | // {{{ nextResult()
|
336 | // {{{ nextResult()
|
337 | 337 | ||
338 | /**
|
338 | /**
|
339 | * Move the internal mysql result pointer to the next available result
|
339 | * Move the internal mysql result pointer to the next available result
|
340 | *
|
340 | *
|
341 | * This method has not been implemented yet.
|
341 | * This method has not been implemented yet.
|
342 | *
|
342 | *
|
343 | * @param a valid sql result resource
|
343 | * @param a valid sql result resource
|
344 | *
|
344 | *
|
345 | * @return false
|
345 | * @return false
|
346 | */
|
346 | */
|
347 | function nextResult($result) |
347 | function nextResult($result) |
348 | {
|
348 | {
|
349 | return false; |
349 | return false; |
350 | }
|
350 | }
|
351 | 351 | ||
352 | // }}}
|
352 | // }}}
|
353 | // {{{ fetchInto()
|
353 | // {{{ fetchInto()
|
354 | 354 | ||
355 | /**
|
355 | /**
|
356 | * Places a row from the result set into the given array
|
356 | * Places a row from the result set into the given array
|
357 | *
|
357 | *
|
358 | * Formating of the array and the data therein are configurable.
|
358 | * Formating of the array and the data therein are configurable.
|
359 | * See DB_result::fetchInto() for more information.
|
359 | * See DB_result::fetchInto() for more information.
|
360 | *
|
360 | *
|
361 | * This method is not meant to be called directly. Use
|
361 | * This method is not meant to be called directly. Use
|
362 | * DB_result::fetchInto() instead. It can't be declared "protected"
|
362 | * DB_result::fetchInto() instead. It can't be declared "protected"
|
363 | * because DB_result is a separate object.
|
363 | * because DB_result is a separate object.
|
364 | *
|
364 | *
|
365 | * @param resource $result the query result resource
|
365 | * @param resource $result the query result resource
|
366 | * @param array $arr the referenced array to put the data in
|
366 | * @param array $arr the referenced array to put the data in
|
367 | * @param int $fetchmode how the resulting array should be indexed
|
367 | * @param int $fetchmode how the resulting array should be indexed
|
368 | * @param int $rownum the row number to fetch (0 = first row)
|
368 | * @param int $rownum the row number to fetch (0 = first row)
|
369 | *
|
369 | *
|
370 | * @return mixed DB_OK on success, NULL when the end of a result set is
|
370 | * @return mixed DB_OK on success, NULL when the end of a result set is
|
371 | * reached or on failure
|
371 | * reached or on failure
|
372 | *
|
372 | *
|
373 | * @see DB_result::fetchInto()
|
373 | * @see DB_result::fetchInto()
|
374 | */
|
374 | */
|
375 | function fetchInto($result, &$arr, $fetchmode, $rownum = null) |
375 | function fetchInto($result, &$arr, $fetchmode, $rownum = null) |
376 | {
|
376 | {
|
377 | if ($rownum !== null) { |
377 | if ($rownum !== null) { |
378 | if (!@mysql_data_seek($result, $rownum)) { |
378 | if (!@mysql_data_seek($result, $rownum)) { |
379 | return null; |
379 | return null; |
380 | }
|
380 | }
|
381 | }
|
381 | }
|
382 | if ($fetchmode & DB_FETCHMODE_ASSOC) { |
382 | if ($fetchmode & DB_FETCHMODE_ASSOC) { |
383 | $arr = @mysql_fetch_array($result, MYSQL_ASSOC); |
383 | $arr = @mysql_fetch_array($result, MYSQL_ASSOC); |
384 | if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) { |
384 | if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) { |
385 | $arr = array_change_key_case($arr, CASE_LOWER); |
385 | $arr = array_change_key_case($arr, CASE_LOWER); |
386 | }
|
386 | }
|
387 | } else { |
387 | } else { |
388 | $arr = @mysql_fetch_row($result); |
388 | $arr = @mysql_fetch_row($result); |
389 | }
|
389 | }
|
390 | if (!$arr) { |
390 | if (!$arr) { |
391 | return null; |
391 | return null; |
392 | }
|
392 | }
|
393 | if ($this->options['portability'] & DB_PORTABILITY_RTRIM) { |
393 | if ($this->options['portability'] & DB_PORTABILITY_RTRIM) { |
394 | /*
|
394 | /*
|
395 | * Even though this DBMS already trims output, we do this because
|
395 | * Even though this DBMS already trims output, we do this because
|
396 | * a field might have intentional whitespace at the end that
|
396 | * a field might have intentional whitespace at the end that
|
397 | * gets removed by DB_PORTABILITY_RTRIM under another driver.
|
397 | * gets removed by DB_PORTABILITY_RTRIM under another driver.
|
398 | */
|
398 | */
|
399 | $this->_rtrimArrayValues($arr); |
399 | $this->_rtrimArrayValues($arr); |
400 | }
|
400 | }
|
401 | if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) { |
401 | if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) { |
402 | $this->_convertNullArrayValuesToEmpty($arr); |
402 | $this->_convertNullArrayValuesToEmpty($arr); |
403 | }
|
403 | }
|
404 | return DB_OK; |
404 | return DB_OK; |
405 | }
|
405 | }
|
406 | 406 | ||
407 | // }}}
|
407 | // }}}
|
408 | // {{{ freeResult()
|
408 | // {{{ freeResult()
|
409 | 409 | ||
410 | /**
|
410 | /**
|
411 | * Deletes the result set and frees the memory occupied by the result set
|
411 | * Deletes the result set and frees the memory occupied by the result set
|
412 | *
|
412 | *
|
413 | * This method is not meant to be called directly. Use
|
413 | * This method is not meant to be called directly. Use
|
414 | * DB_result::free() instead. It can't be declared "protected"
|
414 | * DB_result::free() instead. It can't be declared "protected"
|
415 | * because DB_result is a separate object.
|
415 | * because DB_result is a separate object.
|
416 | *
|
416 | *
|
417 | * @param resource $result PHP's query result resource
|
417 | * @param resource $result PHP's query result resource
|
418 | *
|
418 | *
|
419 | * @return bool TRUE on success, FALSE if $result is invalid
|
419 | * @return bool TRUE on success, FALSE if $result is invalid
|
420 | *
|
420 | *
|
421 | * @see DB_result::free()
|
421 | * @see DB_result::free()
|
422 | */
|
422 | */
|
423 | function freeResult($result) |
423 | function freeResult($result) |
424 | {
|
424 | {
|
425 | return is_resource($result) ? mysql_free_result($result) : false; |
425 | return is_resource($result) ? mysql_free_result($result) : false; |
426 | }
|
426 | }
|
427 | 427 | ||
428 | // }}}
|
428 | // }}}
|
429 | // {{{ numCols()
|
429 | // {{{ numCols()
|
430 | 430 | ||
431 | /**
|
431 | /**
|
432 | * Gets the number of columns in a result set
|
432 | * Gets the number of columns in a result set
|
433 | *
|
433 | *
|
434 | * This method is not meant to be called directly. Use
|
434 | * This method is not meant to be called directly. Use
|
435 | * DB_result::numCols() instead. It can't be declared "protected"
|
435 | * DB_result::numCols() instead. It can't be declared "protected"
|
436 | * because DB_result is a separate object.
|
436 | * because DB_result is a separate object.
|
437 | *
|
437 | *
|
438 | * @param resource $result PHP's query result resource
|
438 | * @param resource $result PHP's query result resource
|
439 | *
|
439 | *
|
440 | * @return int the number of columns. A DB_Error object on failure.
|
440 | * @return int the number of columns. A DB_Error object on failure.
|
441 | *
|
441 | *
|
442 | * @see DB_result::numCols()
|
442 | * @see DB_result::numCols()
|
443 | */
|
443 | */
|
444 | function numCols($result) |
444 | function numCols($result) |
445 | {
|
445 | {
|
446 | $cols = @mysql_num_fields($result); |
446 | $cols = @mysql_num_fields($result); |
447 | if (!$cols) { |
447 | if (!$cols) { |
448 | return $this->mysqlRaiseError(); |
448 | return $this->mysqlRaiseError(); |
449 | }
|
449 | }
|
450 | return $cols; |
450 | return $cols; |
451 | }
|
451 | }
|
452 | 452 | ||
453 | // }}}
|
453 | // }}}
|
454 | // {{{ numRows()
|
454 | // {{{ numRows()
|
455 | 455 | ||
456 | /**
|
456 | /**
|
457 | * Gets the number of rows in a result set
|
457 | * Gets the number of rows in a result set
|
458 | *
|
458 | *
|
459 | * This method is not meant to be called directly. Use
|
459 | * This method is not meant to be called directly. Use
|
460 | * DB_result::numRows() instead. It can't be declared "protected"
|
460 | * DB_result::numRows() instead. It can't be declared "protected"
|
461 | * because DB_result is a separate object.
|
461 | * because DB_result is a separate object.
|
462 | *
|
462 | *
|
463 | * @param resource $result PHP's query result resource
|
463 | * @param resource $result PHP's query result resource
|
464 | *
|
464 | *
|
465 | * @return int the number of rows. A DB_Error object on failure.
|
465 | * @return int the number of rows. A DB_Error object on failure.
|
466 | *
|
466 | *
|
467 | * @see DB_result::numRows()
|
467 | * @see DB_result::numRows()
|
468 | */
|
468 | */
|
469 | function numRows($result) |
469 | function numRows($result) |
470 | {
|
470 | {
|
471 | $rows = @mysql_num_rows($result); |
471 | $rows = @mysql_num_rows($result); |
472 | if ($rows === null) { |
472 | if ($rows === null) { |
473 | return $this->mysqlRaiseError(); |
473 | return $this->mysqlRaiseError(); |
474 | }
|
474 | }
|
475 | return $rows; |
475 | return $rows; |
476 | }
|
476 | }
|
477 | 477 | ||
478 | // }}}
|
478 | // }}}
|
479 | // {{{ autoCommit()
|
479 | // {{{ autoCommit()
|
480 | 480 | ||
481 | /**
|
481 | /**
|
482 | * Enables or disables automatic commits
|
482 | * Enables or disables automatic commits
|
483 | *
|
483 | *
|
484 | * @param bool $onoff true turns it on, false turns it off
|
484 | * @param bool $onoff true turns it on, false turns it off
|
485 | *
|
485 | *
|
486 | * @return int DB_OK on success. A DB_Error object if the driver
|
486 | * @return int DB_OK on success. A DB_Error object if the driver
|
487 | * doesn't support auto-committing transactions.
|
487 | * doesn't support auto-committing transactions.
|
488 | */
|
488 | */
|
489 | function autoCommit($onoff = false) |
489 | function autoCommit($onoff = false) |
490 | {
|
490 | {
|
491 | // XXX if $this->transaction_opcount > 0, we should probably
|
491 | // XXX if $this->transaction_opcount > 0, we should probably
|
492 | // issue a warning here.
|
492 | // issue a warning here.
|
493 | $this->autocommit = $onoff ? true : false; |
493 | $this->autocommit = $onoff ? true : false; |
494 | return DB_OK; |
494 | return DB_OK; |
495 | }
|
495 | }
|
496 | 496 | ||
497 | // }}}
|
497 | // }}}
|
498 | // {{{ commit()
|
498 | // {{{ commit()
|
499 | 499 | ||
500 | /**
|
500 | /**
|
501 | * Commits the current transaction
|
501 | * Commits the current transaction
|
502 | *
|
502 | *
|
503 | * @return int DB_OK on success. A DB_Error object on failure.
|
503 | * @return int DB_OK on success. A DB_Error object on failure.
|
504 | */
|
504 | */
|
505 | function commit() |
505 | function commit() |
506 | {
|
506 | {
|
507 | if ($this->transaction_opcount > 0) { |
507 | if ($this->transaction_opcount > 0) { |
508 | if ($this->_db) { |
508 | if ($this->_db) { |
509 | if (!@mysql_select_db($this->_db, $this->connection)) { |
509 | if (!@mysql_select_db($this->_db, $this->connection)) { |
510 | return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); |
510 | return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); |
511 | }
|
511 | }
|
512 | }
|
512 | }
|
513 | $result = @mysql_query('COMMIT', $this->connection); |
513 | $result = @mysql_query('COMMIT', $this->connection); |
514 | $result = @mysql_query('SET AUTOCOMMIT=1', $this->connection); |
514 | $result = @mysql_query('SET AUTOCOMMIT=1', $this->connection); |
515 | $this->transaction_opcount = 0; |
515 | $this->transaction_opcount = 0; |
516 | if (!$result) { |
516 | if (!$result) { |
517 | return $this->mysqlRaiseError(); |
517 | return $this->mysqlRaiseError(); |
518 | }
|
518 | }
|
519 | }
|
519 | }
|
520 | return DB_OK; |
520 | return DB_OK; |
521 | }
|
521 | }
|
522 | 522 | ||
523 | // }}}
|
523 | // }}}
|
524 | // {{{ rollback()
|
524 | // {{{ rollback()
|
525 | 525 | ||
526 | /**
|
526 | /**
|
527 | * Reverts the current transaction
|
527 | * Reverts the current transaction
|
528 | *
|
528 | *
|
529 | * @return int DB_OK on success. A DB_Error object on failure.
|
529 | * @return int DB_OK on success. A DB_Error object on failure.
|
530 | */
|
530 | */
|
531 | function rollback() |
531 | function rollback() |
532 | {
|
532 | {
|
533 | if ($this->transaction_opcount > 0) { |
533 | if ($this->transaction_opcount > 0) { |
534 | if ($this->_db) { |
534 | if ($this->_db) { |
535 | if (!@mysql_select_db($this->_db, $this->connection)) { |
535 | if (!@mysql_select_db($this->_db, $this->connection)) { |
536 | return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); |
536 | return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); |
537 | }
|
537 | }
|
538 | }
|
538 | }
|
539 | $result = @mysql_query('ROLLBACK', $this->connection); |
539 | $result = @mysql_query('ROLLBACK', $this->connection); |
540 | $result = @mysql_query('SET AUTOCOMMIT=1', $this->connection); |
540 | $result = @mysql_query('SET AUTOCOMMIT=1', $this->connection); |
541 | $this->transaction_opcount = 0; |
541 | $this->transaction_opcount = 0; |
542 | if (!$result) { |
542 | if (!$result) { |
543 | return $this->mysqlRaiseError(); |
543 | return $this->mysqlRaiseError(); |
544 | }
|
544 | }
|
545 | }
|
545 | }
|
546 | return DB_OK; |
546 | return DB_OK; |
547 | }
|
547 | }
|
548 | 548 | ||
549 | // }}}
|
549 | // }}}
|
550 | // {{{ affectedRows()
|
550 | // {{{ affectedRows()
|
551 | 551 | ||
552 | /**
|
552 | /**
|
553 | * Determines the number of rows affected by a data maniuplation query
|
553 | * Determines the number of rows affected by a data maniuplation query
|
554 | *
|
554 | *
|
555 | * 0 is returned for queries that don't manipulate data.
|
555 | * 0 is returned for queries that don't manipulate data.
|
556 | *
|
556 | *
|
557 | * @return int the number of rows. A DB_Error object on failure.
|
557 | * @return int the number of rows. A DB_Error object on failure.
|
558 | */
|
558 | */
|
559 | function affectedRows() |
559 | function affectedRows() |
560 | {
|
560 | {
|
561 | if ($this->_last_query_manip) { |
561 | if ($this->_last_query_manip) { |
562 | return @mysql_affected_rows($this->connection); |
562 | return @mysql_affected_rows($this->connection); |
563 | } else { |
563 | } else { |
564 | return 0; |
564 | return 0; |
565 | }
|
565 | }
|
566 | }
|
566 | }
|
567 | 567 | ||
568 | // }}}
|
568 | // }}}
|
569 | // {{{ nextId()
|
569 | // {{{ nextId()
|
570 | 570 | ||
571 | /**
|
571 | /**
|
572 | * Returns the next free id in a sequence
|
572 | * Returns the next free id in a sequence
|
573 | *
|
573 | *
|
574 | * @param string $seq_name name of the sequence
|
574 | * @param string $seq_name name of the sequence
|
575 | * @param boolean $ondemand when true, the seqence is automatically
|
575 | * @param boolean $ondemand when true, the seqence is automatically
|
576 | * created if it does not exist
|
576 | * created if it does not exist
|
577 | *
|
577 | *
|
578 | * @return int the next id number in the sequence.
|
578 | * @return int the next id number in the sequence.
|
579 | * A DB_Error object on failure.
|
579 | * A DB_Error object on failure.
|
580 | *
|
580 | *
|
581 | * @see DB_common::nextID(), DB_common::getSequenceName(),
|
581 | * @see DB_common::nextID(), DB_common::getSequenceName(),
|
582 | * DB_mysql::createSequence(), DB_mysql::dropSequence()
|
582 | * DB_mysql::createSequence(), DB_mysql::dropSequence()
|
583 | */
|
583 | */
|
584 | function nextId($seq_name, $ondemand = true) |
584 | function nextId($seq_name, $ondemand = true) |
585 | {
|
585 | {
|
586 | $seqname = $this->getSequenceName($seq_name); |
586 | $seqname = $this->getSequenceName($seq_name); |
587 | do { |
587 | do { |
588 | $repeat = 0; |
588 | $repeat = 0; |
589 | $this->pushErrorHandling(PEAR_ERROR_RETURN); |
589 | $this->pushErrorHandling(PEAR_ERROR_RETURN); |
590 | $result = $this->query("UPDATE ${seqname} ". |
590 | $result = $this->query("UPDATE ${seqname} ". |
591 | 'SET id=LAST_INSERT_ID(id+1)'); |
591 | 'SET id=LAST_INSERT_ID(id+1)'); |
592 | $this->popErrorHandling(); |
592 | $this->popErrorHandling(); |
593 | if ($result === DB_OK) { |
593 | if ($result === DB_OK) { |
594 | // COMMON CASE
|
594 | // COMMON CASE
|
595 | $id = @mysql_insert_id($this->connection); |
595 | $id = @mysql_insert_id($this->connection); |
596 | if ($id != 0) { |
596 | if ($id != 0) { |
597 | return $id; |
597 | return $id; |
598 | }
|
598 | }
|
599 | // EMPTY SEQ TABLE
|
599 | // EMPTY SEQ TABLE
|
600 | // Sequence table must be empty for some reason, so fill
|
600 | // Sequence table must be empty for some reason, so fill
|
601 | // it and return 1 and obtain a user-level lock
|
601 | // it and return 1 and obtain a user-level lock
|
602 | $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)"); |
602 | $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)"); |
603 | if (DB::isError($result)) { |
603 | if (DB::isError($result)) { |
604 | return $this->raiseError($result); |
604 | return $this->raiseError($result); |
605 | }
|
605 | }
|
606 | if ($result == 0) { |
606 | if ($result == 0) { |
607 | // Failed to get the lock
|
607 | // Failed to get the lock
|
608 | return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED); |
608 | return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED); |
609 | }
|
609 | }
|
610 | 610 | ||
611 | // add the default value
|
611 | // add the default value
|
612 | $result = $this->query("REPLACE INTO ${seqname} (id) VALUES (0)"); |
612 | $result = $this->query("REPLACE INTO ${seqname} (id) VALUES (0)"); |
613 | if (DB::isError($result)) { |
613 | if (DB::isError($result)) { |
614 | return $this->raiseError($result); |
614 | return $this->raiseError($result); |
615 | }
|
615 | }
|
616 | 616 | ||
617 | // Release the lock
|
617 | // Release the lock
|
618 | $result = $this->getOne('SELECT RELEASE_LOCK(' |
618 | $result = $this->getOne('SELECT RELEASE_LOCK(' |
619 | . "'${seqname}_lock')"); |
619 | . "'${seqname}_lock')"); |
620 | if (DB::isError($result)) { |
620 | if (DB::isError($result)) { |
621 | return $this->raiseError($result); |
621 | return $this->raiseError($result); |
622 | }
|
622 | }
|
623 | // We know what the result will be, so no need to try again
|
623 | // We know what the result will be, so no need to try again
|
624 | return 1; |
624 | return 1; |
625 | 625 | ||
626 | } elseif ($ondemand && DB::isError($result) && |
626 | } elseif ($ondemand && DB::isError($result) && |
627 | $result->getCode() == DB_ERROR_NOSUCHTABLE) |
627 | $result->getCode() == DB_ERROR_NOSUCHTABLE) |
628 | {
|
628 | {
|
629 | // ONDEMAND TABLE CREATION
|
629 | // ONDEMAND TABLE CREATION
|
630 | $result = $this->createSequence($seq_name); |
630 | $result = $this->createSequence($seq_name); |
631 | if (DB::isError($result)) { |
631 | if (DB::isError($result)) { |
632 | return $this->raiseError($result); |
632 | return $this->raiseError($result); |
633 | } else { |
633 | } else { |
634 | $repeat = 1; |
634 | $repeat = 1; |
635 | }
|
635 | }
|
636 | 636 | ||
637 | } elseif (DB::isError($result) && |
637 | } elseif (DB::isError($result) && |
638 | $result->getCode() == DB_ERROR_ALREADY_EXISTS) |
638 | $result->getCode() == DB_ERROR_ALREADY_EXISTS) |
639 | {
|
639 | {
|
640 | // BACKWARDS COMPAT
|
640 | // BACKWARDS COMPAT
|
641 | // see _BCsequence() comment
|
641 | // see _BCsequence() comment
|
642 | $result = $this->_BCsequence($seqname); |
642 | $result = $this->_BCsequence($seqname); |
643 | if (DB::isError($result)) { |
643 | if (DB::isError($result)) { |
644 | return $this->raiseError($result); |
644 | return $this->raiseError($result); |
645 | }
|
645 | }
|
646 | $repeat = 1; |
646 | $repeat = 1; |
647 | }
|
647 | }
|
648 | } while ($repeat); |
648 | } while ($repeat); |
649 | 649 | ||
650 | return $this->raiseError($result); |
650 | return $this->raiseError($result); |
651 | }
|
651 | }
|
652 | 652 | ||
653 | // }}}
|
653 | // }}}
|
654 | // {{{ createSequence()
|
654 | // {{{ createSequence()
|
655 | 655 | ||
656 | /**
|
656 | /**
|
657 | * Creates a new sequence
|
657 | * Creates a new sequence
|
658 | *
|
658 | *
|
659 | * @param string $seq_name name of the new sequence
|
659 | * @param string $seq_name name of the new sequence
|
660 | *
|
660 | *
|
661 | * @return int DB_OK on success. A DB_Error object on failure.
|
661 | * @return int DB_OK on success. A DB_Error object on failure.
|
662 | *
|
662 | *
|
663 | * @see DB_common::createSequence(), DB_common::getSequenceName(),
|
663 | * @see DB_common::createSequence(), DB_common::getSequenceName(),
|
664 | * DB_mysql::nextID(), DB_mysql::dropSequence()
|
664 | * DB_mysql::nextID(), DB_mysql::dropSequence()
|
665 | */
|
665 | */
|
666 | function createSequence($seq_name) |
666 | function createSequence($seq_name) |
667 | {
|
667 | {
|
668 | $seqname = $this->getSequenceName($seq_name); |
668 | $seqname = $this->getSequenceName($seq_name); |
669 | $res = $this->query('CREATE TABLE ' . $seqname |
669 | $res = $this->query('CREATE TABLE ' . $seqname |
670 | . ' (id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,' |
670 | . ' (id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,' |
671 | . ' PRIMARY KEY(id))'); |
671 | . ' PRIMARY KEY(id))'); |
672 | if (DB::isError($res)) { |
672 | if (DB::isError($res)) { |
673 | return $res; |
673 | return $res; |
674 | }
|
674 | }
|
675 | // insert yields value 1, nextId call will generate ID 2
|
675 | // insert yields value 1, nextId call will generate ID 2
|
676 | $res = $this->query("INSERT INTO ${seqname} (id) VALUES (0)"); |
676 | $res = $this->query("INSERT INTO ${seqname} (id) VALUES (0)"); |
677 | if (DB::isError($res)) { |
677 | if (DB::isError($res)) { |
678 | return $res; |
678 | return $res; |
679 | }
|
679 | }
|
680 | // so reset to zero
|
680 | // so reset to zero
|
681 | return $this->query("UPDATE ${seqname} SET id = 0"); |
681 | return $this->query("UPDATE ${seqname} SET id = 0"); |
682 | }
|
682 | }
|
683 | 683 | ||
684 | // }}}
|
684 | // }}}
|
685 | // {{{ dropSequence()
|
685 | // {{{ dropSequence()
|
686 | 686 | ||
687 | /**
|
687 | /**
|
688 | * Deletes a sequence
|
688 | * Deletes a sequence
|
689 | *
|
689 | *
|
690 | * @param string $seq_name name of the sequence to be deleted
|
690 | * @param string $seq_name name of the sequence to be deleted
|
691 | *
|
691 | *
|
692 | * @return int DB_OK on success. A DB_Error object on failure.
|
692 | * @return int DB_OK on success. A DB_Error object on failure.
|
693 | *
|
693 | *
|
694 | * @see DB_common::dropSequence(), DB_common::getSequenceName(),
|
694 | * @see DB_common::dropSequence(), DB_common::getSequenceName(),
|
695 | * DB_mysql::nextID(), DB_mysql::createSequence()
|
695 | * DB_mysql::nextID(), DB_mysql::createSequence()
|
696 | */
|
696 | */
|
697 | function dropSequence($seq_name) |
697 | function dropSequence($seq_name) |
698 | {
|
698 | {
|
699 | return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name)); |
699 | return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name)); |
700 | }
|
700 | }
|
701 | 701 | ||
702 | // }}}
|
702 | // }}}
|
703 | // {{{ _BCsequence()
|
703 | // {{{ _BCsequence()
|
704 | 704 | ||
705 | /**
|
705 | /**
|
706 | * Backwards compatibility with old sequence emulation implementation
|
706 | * Backwards compatibility with old sequence emulation implementation
|
707 | * (clean up the dupes)
|
707 | * (clean up the dupes)
|
708 | *
|
708 | *
|
709 | * @param string $seqname the sequence name to clean up
|
709 | * @param string $seqname the sequence name to clean up
|
710 | *
|
710 | *
|
711 | * @return bool true on success. A DB_Error object on failure.
|
711 | * @return bool true on success. A DB_Error object on failure.
|
712 | *
|
712 | *
|
713 | * @access private
|
713 | * @access private
|
714 | */
|
714 | */
|
715 | function _BCsequence($seqname) |
715 | function _BCsequence($seqname) |
716 | {
|
716 | {
|
717 | // Obtain a user-level lock... this will release any previous
|
717 | // Obtain a user-level lock... this will release any previous
|
718 | // application locks, but unlike LOCK TABLES, it does not abort
|
718 | // application locks, but unlike LOCK TABLES, it does not abort
|
719 | // the current transaction and is much less frequently used.
|
719 | // the current transaction and is much less frequently used.
|
720 | $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)"); |
720 | $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)"); |
721 | if (DB::isError($result)) { |
721 | if (DB::isError($result)) { |
722 | return $result; |
722 | return $result; |
723 | }
|
723 | }
|
724 | if ($result == 0) { |
724 | if ($result == 0) { |
725 | // Failed to get the lock, can't do the conversion, bail
|
725 | // Failed to get the lock, can't do the conversion, bail
|
726 | // with a DB_ERROR_NOT_LOCKED error
|
726 | // with a DB_ERROR_NOT_LOCKED error
|
727 | return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED); |
727 | return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED); |
728 | }
|
728 | }
|
729 | 729 | ||
730 | $highest_id = $this->getOne("SELECT MAX(id) FROM ${seqname}"); |
730 | $highest_id = $this->getOne("SELECT MAX(id) FROM ${seqname}"); |
731 | if (DB::isError($highest_id)) { |
731 | if (DB::isError($highest_id)) { |
732 | return $highest_id; |
732 | return $highest_id; |
733 | }
|
733 | }
|
734 | // This should kill all rows except the highest
|
734 | // This should kill all rows except the highest
|
735 | // We should probably do something if $highest_id isn't
|
735 | // We should probably do something if $highest_id isn't
|
736 | // numeric, but I'm at a loss as how to handle that...
|
736 | // numeric, but I'm at a loss as how to handle that...
|
737 | $result = $this->query('DELETE FROM ' . $seqname |
737 | $result = $this->query('DELETE FROM ' . $seqname |
738 | . " WHERE id <> $highest_id"); |
738 | . " WHERE id <> $highest_id"); |
739 | if (DB::isError($result)) { |
739 | if (DB::isError($result)) { |
740 | return $result; |
740 | return $result; |
741 | }
|
741 | }
|
742 | 742 | ||
743 | // If another thread has been waiting for this lock,
|
743 | // If another thread has been waiting for this lock,
|
744 | // it will go thru the above procedure, but will have no
|
744 | // it will go thru the above procedure, but will have no
|
745 | // real effect
|
745 | // real effect
|
746 | $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')"); |
746 | $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')"); |
747 | if (DB::isError($result)) { |
747 | if (DB::isError($result)) { |
748 | return $result; |
748 | return $result; |
749 | }
|
749 | }
|
750 | return true; |
750 | return true; |
751 | }
|
751 | }
|
752 | 752 | ||
753 | // }}}
|
753 | // }}}
|
754 | // {{{ quoteIdentifier()
|
754 | // {{{ quoteIdentifier()
|
755 | 755 | ||
756 | /**
|
756 | /**
|
757 | * Quotes a string so it can be safely used as a table or column name
|
757 | * Quotes a string so it can be safely used as a table or column name
|
758 | * (WARNING: using names that require this is a REALLY BAD IDEA)
|
758 | * (WARNING: using names that require this is a REALLY BAD IDEA)
|
759 | *
|
759 | *
|
760 | * WARNING: Older versions of MySQL can't handle the backtick
|
760 | * WARNING: Older versions of MySQL can't handle the backtick
|
761 | * character (<kbd>`</kbd>) in table or column names.
|
761 | * character (<kbd>`</kbd>) in table or column names.
|
762 | *
|
762 | *
|
763 | * @param string $str identifier name to be quoted
|
763 | * @param string $str identifier name to be quoted
|
764 | *
|
764 | *
|
765 | * @return string quoted identifier string
|
765 | * @return string quoted identifier string
|
766 | *
|
766 | *
|
767 | * @see DB_common::quoteIdentifier()
|
767 | * @see DB_common::quoteIdentifier()
|
768 | * @since Method available since Release 1.6.0
|
768 | * @since Method available since Release 1.6.0
|
769 | */
|
769 | */
|
770 | function quoteIdentifier($str) |
770 | function quoteIdentifier($str) |
771 | {
|
771 | {
|
772 | return '`' . str_replace('`', '``', $str) . '`'; |
772 | return '`' . str_replace('`', '``', $str) . '`'; |
773 | }
|
773 | }
|
774 | 774 | ||
775 | // }}}
|
775 | // }}}
|
776 | // {{{ quote()
|
776 | // {{{ quote()
|
777 | 777 | ||
778 | /**
|
778 | /**
|
779 | * @deprecated Deprecated in release 1.6.0
|
779 | * @deprecated Deprecated in release 1.6.0
|
780 | */
|
780 | */
|
781 | function quote($str) |
781 | function quote($str) |
782 | {
|
782 | {
|
783 | return $this->quoteSmart($str); |
783 | return $this->quoteSmart($str); |
784 | }
|
784 | }
|
785 | 785 | ||
786 | // }}}
|
786 | // }}}
|
787 | // {{{ escapeSimple()
|
787 | // {{{ escapeSimple()
|
788 | 788 | ||
789 | /**
|
789 | /**
|
790 | * Escapes a string according to the current DBMS's standards
|
790 | * Escapes a string according to the current DBMS's standards
|
791 | *
|
791 | *
|
792 | * @param string $str the string to be escaped
|
792 | * @param string $str the string to be escaped
|
793 | *
|
793 | *
|
794 | * @return string the escaped string
|
794 | * @return string the escaped string
|
795 | *
|
795 | *
|
796 | * @see DB_common::quoteSmart()
|
796 | * @see DB_common::quoteSmart()
|
797 | * @since Method available since Release 1.6.0
|
797 | * @since Method available since Release 1.6.0
|
798 | */
|
798 | */
|
799 | function escapeSimple($str) |
799 | function escapeSimple($str) |
800 | {
|
800 | {
|
801 | if (function_exists('mysql_real_escape_string')) { |
801 | if (function_exists('mysql_real_escape_string')) { |
802 | return @mysql_real_escape_string($str, $this->connection); |
802 | return @mysql_real_escape_string($str, $this->connection); |
803 | } else { |
803 | } else { |
804 | return @mysql_escape_string($str); |
804 | return @mysql_escape_string($str); |
805 | }
|
805 | }
|
806 | }
|
806 | }
|
807 | 807 | ||
808 | // }}}
|
808 | // }}}
|
809 | // {{{ modifyQuery()
|
809 | // {{{ modifyQuery()
|
810 | 810 | ||
811 | /**
|
811 | /**
|
812 | * Changes a query string for various DBMS specific reasons
|
812 | * Changes a query string for various DBMS specific reasons
|
813 | *
|
813 | *
|
814 | * This little hack lets you know how many rows were deleted
|
814 | * This little hack lets you know how many rows were deleted
|
815 | * when running a "DELETE FROM table" query. Only implemented
|
815 | * when running a "DELETE FROM table" query. Only implemented
|
816 | * if the DB_PORTABILITY_DELETE_COUNT portability option is on.
|
816 | * if the DB_PORTABILITY_DELETE_COUNT portability option is on.
|
817 | *
|
817 | *
|
818 | * @param string $query the query string to modify
|
818 | * @param string $query the query string to modify
|
819 | *
|
819 | *
|
820 | * @return string the modified query string
|
820 | * @return string the modified query string
|
821 | *
|
821 | *
|
822 | * @access protected
|
822 | * @access protected
|
823 | * @see DB_common::setOption()
|
823 | * @see DB_common::setOption()
|
824 | */
|
824 | */
|
825 | function modifyQuery($query) |
825 | function modifyQuery($query) |
826 | {
|
826 | {
|
827 | if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) { |
827 | if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) { |
828 | // "DELETE FROM table" gives 0 affected rows in MySQL.
|
828 | // "DELETE FROM table" gives 0 affected rows in MySQL.
|
829 | // This little hack lets you know how many rows were deleted.
|
829 | // This little hack lets you know how many rows were deleted.
|
830 | if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) { |
830 | if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) { |
831 | $query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/', |
831 | $query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/', |
832 | 'DELETE FROM \1 WHERE 1=1', $query); |
832 | 'DELETE FROM \1 WHERE 1=1', $query); |
833 | }
|
833 | }
|
834 | }
|
834 | }
|
835 | return $query; |
835 | return $query; |
836 | }
|
836 | }
|
837 | 837 | ||
838 | // }}}
|
838 | // }}}
|
839 | // {{{ modifyLimitQuery()
|
839 | // {{{ modifyLimitQuery()
|
840 | 840 | ||
841 | /**
|
841 | /**
|
842 | * Adds LIMIT clauses to a query string according to current DBMS standards
|
842 | * Adds LIMIT clauses to a query string according to current DBMS standards
|
843 | *
|
843 | *
|
844 | * @param string $query the query to modify
|
844 | * @param string $query the query to modify
|
845 | * @param int $from the row to start to fetching (0 = the first row)
|
845 | * @param int $from the row to start to fetching (0 = the first row)
|
846 | * @param int $count the numbers of rows to fetch
|
846 | * @param int $count the numbers of rows to fetch
|
847 | * @param mixed $params array, string or numeric data to be used in
|
847 | * @param mixed $params array, string or numeric data to be used in
|
848 | * execution of the statement. Quantity of items
|
848 | * execution of the statement. Quantity of items
|
849 | * passed must match quantity of placeholders in
|
849 | * passed must match quantity of placeholders in
|
850 | * query: meaning 1 placeholder for non-array
|
850 | * query: meaning 1 placeholder for non-array
|
851 | * parameters or 1 placeholder per array element.
|
851 | * parameters or 1 placeholder per array element.
|
852 | *
|
852 | *
|
853 | * @return string the query string with LIMIT clauses added
|
853 | * @return string the query string with LIMIT clauses added
|
854 | *
|
854 | *
|
855 | * @access protected
|
855 | * @access protected
|
856 | */
|
856 | */
|
857 | function modifyLimitQuery($query, $from, $count, $params = array()) |
857 | function modifyLimitQuery($query, $from, $count, $params = array()) |
858 | {
|
858 | {
|
859 | if (DB::isManip($query) || $this->_next_query_manip) { |
859 | if (DB::isManip($query) || $this->_next_query_manip) { |
860 | return $query . " LIMIT $count"; |
860 | return $query . " LIMIT $count"; |
861 | } else { |
861 | } else { |
862 | return $query . " LIMIT $from, $count"; |
862 | return $query . " LIMIT $from, $count"; |
863 | }
|
863 | }
|
864 | }
|
864 | }
|
865 | 865 | ||
866 | // }}}
|
866 | // }}}
|
867 | // {{{ mysqlRaiseError()
|
867 | // {{{ mysqlRaiseError()
|
868 | 868 | ||
869 | /**
|
869 | /**
|
870 | * Produces a DB_Error object regarding the current problem
|
870 | * Produces a DB_Error object regarding the current problem
|
871 | *
|
871 | *
|
872 | * @param int $errno if the error is being manually raised pass a
|
872 | * @param int $errno if the error is being manually raised pass a
|
873 | * DB_ERROR* constant here. If this isn't passed
|
873 | * DB_ERROR* constant here. If this isn't passed
|
874 | * the error information gathered from the DBMS.
|
874 | * the error information gathered from the DBMS.
|
875 | *
|
875 | *
|
876 | * @return object the DB_Error object
|
876 | * @return object the DB_Error object
|
877 | *
|
877 | *
|
878 | * @see DB_common::raiseError(),
|
878 | * @see DB_common::raiseError(),
|
879 | * DB_mysql::errorNative(), DB_common::errorCode()
|
879 | * DB_mysql::errorNative(), DB_common::errorCode()
|
880 | */
|
880 | */
|
881 | function mysqlRaiseError($errno = null) |
881 | function mysqlRaiseError($errno = null) |
882 | {
|
882 | {
|
883 | if ($errno === null) { |
883 | if ($errno === null) { |
884 | if ($this->options['portability'] & DB_PORTABILITY_ERRORS) { |
884 | if ($this->options['portability'] & DB_PORTABILITY_ERRORS) { |
885 | $this->errorcode_map[1022] = DB_ERROR_CONSTRAINT; |
885 | $this->errorcode_map[1022] = DB_ERROR_CONSTRAINT; |
886 | $this->errorcode_map[1048] = DB_ERROR_CONSTRAINT_NOT_NULL; |
886 | $this->errorcode_map[1048] = DB_ERROR_CONSTRAINT_NOT_NULL; |
887 | $this->errorcode_map[1062] = DB_ERROR_CONSTRAINT; |
887 | $this->errorcode_map[1062] = DB_ERROR_CONSTRAINT; |
888 | } else { |
888 | } else { |
889 | // Doing this in case mode changes during runtime.
|
889 | // Doing this in case mode changes during runtime.
|
890 | $this->errorcode_map[1022] = DB_ERROR_ALREADY_EXISTS; |
890 | $this->errorcode_map[1022] = DB_ERROR_ALREADY_EXISTS; |
891 | $this->errorcode_map[1048] = DB_ERROR_CONSTRAINT; |
891 | $this->errorcode_map[1048] = DB_ERROR_CONSTRAINT; |
892 | $this->errorcode_map[1062] = DB_ERROR_ALREADY_EXISTS; |
892 | $this->errorcode_map[1062] = DB_ERROR_ALREADY_EXISTS; |
893 | }
|
893 | }
|
894 | $errno = $this->errorCode(mysql_errno($this->connection)); |
894 | $errno = $this->errorCode(mysql_errno($this->connection)); |
895 | }
|
895 | }
|
896 | return $this->raiseError($errno, null, null, null, |
896 | return $this->raiseError($errno, null, null, null, |
897 | @mysql_errno($this->connection) . ' ** ' . |
897 | @mysql_errno($this->connection) . ' ** ' . |
898 | @mysql_error($this->connection)); |
898 | @mysql_error($this->connection)); |
899 | }
|
899 | }
|
900 | 900 | ||
901 | // }}}
|
901 | // }}}
|
902 | // {{{ errorNative()
|
902 | // {{{ errorNative()
|
903 | 903 | ||
904 | /**
|
904 | /**
|
905 | * Gets the DBMS' native error code produced by the last query
|
905 | * Gets the DBMS' native error code produced by the last query
|
906 | *
|
906 | *
|
907 | * @return int the DBMS' error code
|
907 | * @return int the DBMS' error code
|
908 | */
|
908 | */
|
909 | function errorNative() |
909 | function errorNative() |
910 | {
|
910 | {
|
911 | return @mysql_errno($this->connection); |
911 | return @mysql_errno($this->connection); |
912 | }
|
912 | }
|
913 | 913 | ||
914 | // }}}
|
914 | // }}}
|
915 | // {{{ tableInfo()
|
915 | // {{{ tableInfo()
|
916 | 916 | ||
917 | /**
|
917 | /**
|
918 | * Returns information about a table or a result set
|
918 | * Returns information about a table or a result set
|
919 | *
|
919 | *
|
920 | * @param object|string $result DB_result object from a query or a
|
920 | * @param object|string $result DB_result object from a query or a
|
921 | * string containing the name of a table.
|
921 | * string containing the name of a table.
|
922 | * While this also accepts a query result
|
922 | * While this also accepts a query result
|
923 | * resource identifier, this behavior is
|
923 | * resource identifier, this behavior is
|
924 | * deprecated.
|
924 | * deprecated.
|
925 | * @param int $mode a valid tableInfo mode
|
925 | * @param int $mode a valid tableInfo mode
|
926 | *
|
926 | *
|
927 | * @return array an associative array with the information requested.
|
927 | * @return array an associative array with the information requested.
|
928 | * A DB_Error object on failure.
|
928 | * A DB_Error object on failure.
|
929 | *
|
929 | *
|
930 | * @see DB_common::tableInfo()
|
930 | * @see DB_common::tableInfo()
|
931 | */
|
931 | */
|
932 | function tableInfo($result, $mode = null) |
932 | function tableInfo($result, $mode = null) |
933 | {
|
933 | {
|
934 | if (is_string($result)) { |
934 | if (is_string($result)) { |
935 | // Fix for bug #11580.
|
935 | // Fix for bug #11580.
|
936 | if ($this->_db) { |
936 | if ($this->_db) { |
937 | if (!@mysql_select_db($this->_db, $this->connection)) { |
937 | if (!@mysql_select_db($this->_db, $this->connection)) { |
938 | return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); |
938 | return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); |
939 | }
|
939 | }
|
940 | }
|
940 | }
|
941 | 941 | ||
942 | /*
|
942 | /*
|
943 | * Probably received a table name.
|
943 | * Probably received a table name.
|
944 | * Create a result resource identifier.
|
944 | * Create a result resource identifier.
|
945 | */
|
945 | */
|
946 | $id = @mysql_query("SELECT * FROM $result LIMIT 0", |
946 | $id = @mysql_query("SELECT * FROM $result LIMIT 0", |
947 | $this->connection); |
947 | $this->connection); |
948 | $got_string = true; |
948 | $got_string = true; |
949 | } elseif (isset($result->result)) { |
949 | } elseif (isset($result->result)) { |
950 | /*
|
950 | /*
|
951 | * Probably received a result object.
|
951 | * Probably received a result object.
|
952 | * Extract the result resource identifier.
|
952 | * Extract the result resource identifier.
|
953 | */
|
953 | */
|
954 | $id = $result->result; |
954 | $id = $result->result; |
955 | $got_string = false; |
955 | $got_string = false; |
956 | } else { |
956 | } else { |
957 | /*
|
957 | /*
|
958 | * Probably received a result resource identifier.
|
958 | * Probably received a result resource identifier.
|
959 | * Copy it.
|
959 | * Copy it.
|
960 | * Deprecated. Here for compatibility only.
|
960 | * Deprecated. Here for compatibility only.
|
961 | */
|
961 | */
|
962 | $id = $result; |
962 | $id = $result; |
963 | $got_string = false; |
963 | $got_string = false; |
964 | }
|
964 | }
|
965 | 965 | ||
966 | if (!is_resource($id)) { |
966 | if (!is_resource($id)) { |
967 | return $this->mysqlRaiseError(DB_ERROR_NEED_MORE_DATA); |
967 | return $this->mysqlRaiseError(DB_ERROR_NEED_MORE_DATA); |
968 | }
|
968 | }
|
969 | 969 | ||
970 | if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) { |
970 | if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) { |
971 | $case_func = 'strtolower'; |
971 | $case_func = 'strtolower'; |
972 | } else { |
972 | } else { |
973 | $case_func = 'strval'; |
973 | $case_func = 'strval'; |
974 | }
|
974 | }
|
975 | 975 | ||
976 | $count = @mysql_num_fields($id); |
976 | $count = @mysql_num_fields($id); |
977 | $res = array(); |
977 | $res = array(); |
978 | 978 | ||
979 | if ($mode) { |
979 | if ($mode) { |
980 | $res['num_fields'] = $count; |
980 | $res['num_fields'] = $count; |
981 | }
|
981 | }
|
982 | 982 | ||
983 | for ($i = 0; $i < $count; $i++) { |
983 | for ($i = 0; $i < $count; $i++) { |
984 | $res[$i] = array( |
984 | $res[$i] = array( |
985 | 'table' => $case_func(@mysql_field_table($id, $i)), |
985 | 'table' => $case_func(@mysql_field_table($id, $i)), |
986 | 'name' => $case_func(@mysql_field_name($id, $i)), |
986 | 'name' => $case_func(@mysql_field_name($id, $i)), |
987 | 'type' => @mysql_field_type($id, $i), |
987 | 'type' => @mysql_field_type($id, $i), |
988 | 'len' => @mysql_field_len($id, $i), |
988 | 'len' => @mysql_field_len($id, $i), |
989 | 'flags' => @mysql_field_flags($id, $i), |
989 | 'flags' => @mysql_field_flags($id, $i), |
990 | ); |
990 | ); |
991 | if ($mode & DB_TABLEINFO_ORDER) { |
991 | if ($mode & DB_TABLEINFO_ORDER) { |
992 | $res['order'][$res[$i]['name']] = $i; |
992 | $res['order'][$res[$i]['name']] = $i; |
993 | }
|
993 | }
|
994 | if ($mode & DB_TABLEINFO_ORDERTABLE) { |
994 | if ($mode & DB_TABLEINFO_ORDERTABLE) { |
995 | $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i; |
995 | $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i; |
996 | }
|
996 | }
|
997 | }
|
997 | }
|
998 | 998 | ||
999 | // free the result only if we were called on a table
|
999 | // free the result only if we were called on a table
|
1000 | if ($got_string) { |
1000 | if ($got_string) { |
1001 | @mysql_free_result($id); |
1001 | @mysql_free_result($id); |
1002 | }
|
1002 | }
|
1003 | return $res; |
1003 | return $res; |
1004 | }
|
1004 | }
|
1005 | 1005 | ||
1006 | // }}}
|
1006 | // }}}
|
1007 | // {{{ getSpecialQuery()
|
1007 | // {{{ getSpecialQuery()
|
1008 | 1008 | ||
1009 | /**
|
1009 | /**
|
1010 | * Obtains the query string needed for listing a given type of objects
|
1010 | * Obtains the query string needed for listing a given type of objects
|
1011 | *
|
1011 | *
|
1012 | * @param string $type the kind of objects you want to retrieve
|
1012 | * @param string $type the kind of objects you want to retrieve
|
1013 | *
|
1013 | *
|
1014 | * @return string the SQL query string or null if the driver doesn't
|
1014 | * @return string the SQL query string or null if the driver doesn't
|
1015 | * support the object type requested
|
1015 | * support the object type requested
|
1016 | *
|
1016 | *
|
1017 | * @access protected
|
1017 | * @access protected
|
1018 | * @see DB_common::getListOf()
|
1018 | * @see DB_common::getListOf()
|
1019 | */
|
1019 | */
|
1020 | function getSpecialQuery($type) |
1020 | function getSpecialQuery($type) |
1021 | {
|
1021 | {
|
1022 | switch ($type) { |
1022 | switch ($type) { |
1023 | case 'tables': |
1023 | case 'tables': |
1024 | return 'SHOW TABLES'; |
1024 | return 'SHOW TABLES'; |
1025 | case 'users': |
1025 | case 'users': |
1026 | return 'SELECT DISTINCT User FROM mysql.user'; |
1026 | return 'SELECT DISTINCT User FROM mysql.user'; |
1027 | case 'databases': |
1027 | case 'databases': |
1028 | return 'SHOW DATABASES'; |
1028 | return 'SHOW DATABASES'; |
1029 | default: |
1029 | default: |
1030 | return null; |
1030 | return null; |
1031 | }
|
1031 | }
|
1032 | }
|
1032 | }
|
1033 | 1033 | ||
1034 | // }}}
|
1034 | // }}}
|
1035 | 1035 | ||
1036 | }
|
1036 | }
|
1037 | 1037 | ||
1038 | /*
|
1038 | /*
|
1039 | * Local variables:
|
1039 | * Local variables:
|
1040 | * tab-width: 4
|
1040 | * tab-width: 4
|
1041 | * c-basic-offset: 4
|
1041 | * c-basic-offset: 4
|
1042 | * End:
|
1042 | * End:
|
1043 | */
|
1043 | */
|
1044 | 1044 | ||
1045 | ?>
|
1045 | ?>
|
1046 | 1046 |