Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 31 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 31 Rev 316
1
<?php
1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
2
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
3
// +----------------------------------------------------------------------+
3
// +----------------------------------------------------------------------+
4
// | PHP Version 4                                                        |
4
// | PHP Version 4                                                        |
5
// +----------------------------------------------------------------------+
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 1997-2004 The PHP Group                                |
6
// | Copyright (c) 1997-2004 The PHP Group                                |
7
// +----------------------------------------------------------------------+
7
// +----------------------------------------------------------------------+
8
// | This source file is subject to version 2.02 of the PHP license,      |
8
// | This source file is subject to version 2.02 of the PHP license,      |
9
// | that is bundled with this package in the file LICENSE, and is        |
9
// | that is bundled with this package in the file LICENSE, and is        |
10
// | available at through the world-wide-web at                           |
10
// | available at through the world-wide-web at                           |
11
// | http://www.php.net/license/2_02.txt.                                 |
11
// | http://www.php.net/license/2_02.txt.                                 |
12
// | If you did not receive a copy of the PHP license and are unable to   |
12
// | If you did not receive a copy of the PHP license and are unable to   |
13
// | obtain it through the world-wide-web, please send a note to          |
13
// | obtain it through the world-wide-web, please send a note to          |
14
// | license@php.net so we can mail you a copy immediately.               |
14
// | license@php.net so we can mail you a copy immediately.               |
15
// +----------------------------------------------------------------------+
15
// +----------------------------------------------------------------------+
16
// | Authors: Stig Bakken <ssb@php.net>                                   |
16
// | Authors: Stig Bakken <ssb@php.net>                                   |
17
// |          Tomas V.V.Cox <cox@idecnet.com>                             |
17
// |          Tomas V.V.Cox <cox@idecnet.com>                             |
18
// | Maintainer: Daniel Convissor <danielc@php.net>                       |
18
// | Maintainer: Daniel Convissor <danielc@php.net>                       |
19
// +----------------------------------------------------------------------+
19
// +----------------------------------------------------------------------+
20
//
20
//
21
// $Id$
21
// $Id$
22
//
22
//
23
// Database independent query interface.
23
// Database independent query interface.
24
 
24
 
25
 
25
 
26
require_once 'PEAR.php';
26
require_once 'PEAR.php';
27
 
27
 
28
// {{{ constants
28
// {{{ constants
29
// {{{ error codes
29
// {{{ error codes
30
 
30
 
31
/*
31
/*
32
 * The method mapErrorCode in each DB_dbtype implementation maps
32
 * The method mapErrorCode in each DB_dbtype implementation maps
33
 * native error codes to one of these.
33
 * native error codes to one of these.
34
 *
34
 *
35
 * If you add an error code here, make sure you also add a textual
35
 * If you add an error code here, make sure you also add a textual
36
 * version of it in DB::errorMessage().
36
 * version of it in DB::errorMessage().
37
 */
37
 */
38
define('DB_OK',                         1);
38
define('DB_OK',                         1);
39
define('DB_ERROR',                     -1);
39
define('DB_ERROR',                     -1);
40
define('DB_ERROR_SYNTAX',              -2);
40
define('DB_ERROR_SYNTAX',              -2);
41
define('DB_ERROR_CONSTRAINT',          -3);
41
define('DB_ERROR_CONSTRAINT',          -3);
42
define('DB_ERROR_NOT_FOUND',           -4);
42
define('DB_ERROR_NOT_FOUND',           -4);
43
define('DB_ERROR_ALREADY_EXISTS',      -5);
43
define('DB_ERROR_ALREADY_EXISTS',      -5);
44
define('DB_ERROR_UNSUPPORTED',         -6);
44
define('DB_ERROR_UNSUPPORTED',         -6);
45
define('DB_ERROR_MISMATCH',            -7);
45
define('DB_ERROR_MISMATCH',            -7);
46
define('DB_ERROR_INVALID',             -8);
46
define('DB_ERROR_INVALID',             -8);
47
define('DB_ERROR_NOT_CAPABLE',         -9);
47
define('DB_ERROR_NOT_CAPABLE',         -9);
48
define('DB_ERROR_TRUNCATED',          -10);
48
define('DB_ERROR_TRUNCATED',          -10);
49
define('DB_ERROR_INVALID_NUMBER',     -11);
49
define('DB_ERROR_INVALID_NUMBER',     -11);
50
define('DB_ERROR_INVALID_DATE',       -12);
50
define('DB_ERROR_INVALID_DATE',       -12);
51
define('DB_ERROR_DIVZERO',            -13);
51
define('DB_ERROR_DIVZERO',            -13);
52
define('DB_ERROR_NODBSELECTED',       -14);
52
define('DB_ERROR_NODBSELECTED',       -14);
53
define('DB_ERROR_CANNOT_CREATE',      -15);
53
define('DB_ERROR_CANNOT_CREATE',      -15);
54
define('DB_ERROR_CANNOT_DELETE',      -16);
54
define('DB_ERROR_CANNOT_DELETE',      -16);
55
define('DB_ERROR_CANNOT_DROP',        -17);
55
define('DB_ERROR_CANNOT_DROP',        -17);
56
define('DB_ERROR_NOSUCHTABLE',        -18);
56
define('DB_ERROR_NOSUCHTABLE',        -18);
57
define('DB_ERROR_NOSUCHFIELD',        -19);
57
define('DB_ERROR_NOSUCHFIELD',        -19);
58
define('DB_ERROR_NEED_MORE_DATA',     -20);
58
define('DB_ERROR_NEED_MORE_DATA',     -20);
59
define('DB_ERROR_NOT_LOCKED',         -21);
59
define('DB_ERROR_NOT_LOCKED',         -21);
60
define('DB_ERROR_VALUE_COUNT_ON_ROW', -22);
60
define('DB_ERROR_VALUE_COUNT_ON_ROW', -22);
61
define('DB_ERROR_INVALID_DSN',        -23);
61
define('DB_ERROR_INVALID_DSN',        -23);
62
define('DB_ERROR_CONNECT_FAILED',     -24);
62
define('DB_ERROR_CONNECT_FAILED',     -24);
63
define('DB_ERROR_EXTENSION_NOT_FOUND',-25);
63
define('DB_ERROR_EXTENSION_NOT_FOUND',-25);
64
define('DB_ERROR_ACCESS_VIOLATION',   -26);
64
define('DB_ERROR_ACCESS_VIOLATION',   -26);
65
define('DB_ERROR_NOSUCHDB',           -27);
65
define('DB_ERROR_NOSUCHDB',           -27);
66
define('DB_ERROR_CONSTRAINT_NOT_NULL',-29);
66
define('DB_ERROR_CONSTRAINT_NOT_NULL',-29);
67
 
67
 
68
 
68
 
69
// }}}
69
// }}}
70
// {{{ prepared statement-related
70
// {{{ prepared statement-related
71
 
71
 
72
 
72
 
73
/*
73
/*
74
 * These constants are used when storing information about prepared
74
 * These constants are used when storing information about prepared
75
 * statements (using the "prepare" method in DB_dbtype).
75
 * statements (using the "prepare" method in DB_dbtype).
76
 *
76
 *
77
 * The prepare/execute model in DB is mostly borrowed from the ODBC
77
 * The prepare/execute model in DB is mostly borrowed from the ODBC
78
 * extension, in a query the "?" character means a scalar parameter.
78
 * extension, in a query the "?" character means a scalar parameter.
79
 * There are two extensions though, a "&" character means an opaque
79
 * There are two extensions though, a "&" character means an opaque
80
 * parameter.  An opaque parameter is simply a file name, the real
80
 * parameter.  An opaque parameter is simply a file name, the real
81
 * data are in that file (useful for putting uploaded files into your
81
 * data are in that file (useful for putting uploaded files into your
82
 * database and such). The "!" char means a parameter that must be
82
 * database and such). The "!" char means a parameter that must be
83
 * left as it is.
83
 * left as it is.
84
 * They modify the quote behavoir:
84
 * They modify the quote behavoir:
85
 * DB_PARAM_SCALAR (?) => 'original string quoted'
85
 * DB_PARAM_SCALAR (?) => 'original string quoted'
86
 * DB_PARAM_OPAQUE (&) => 'string from file quoted'
86
 * DB_PARAM_OPAQUE (&) => 'string from file quoted'
87
 * DB_PARAM_MISC   (!) => original string
87
 * DB_PARAM_MISC   (!) => original string
88
 */
88
 */
89
define('DB_PARAM_SCALAR', 1);
89
define('DB_PARAM_SCALAR', 1);
90
define('DB_PARAM_OPAQUE', 2);
90
define('DB_PARAM_OPAQUE', 2);
91
define('DB_PARAM_MISC',   3);
91
define('DB_PARAM_MISC',   3);
92
 
92
 
93
 
93
 
94
// }}}
94
// }}}
95
// {{{ binary data-related
95
// {{{ binary data-related
96
 
96
 
97
 
97
 
98
/*
98
/*
99
 * These constants define different ways of returning binary data
99
 * These constants define different ways of returning binary data
100
 * from queries.  Again, this model has been borrowed from the ODBC
100
 * from queries.  Again, this model has been borrowed from the ODBC
101
 * extension.
101
 * extension.
102
 *
102
 *
103
 * DB_BINMODE_PASSTHRU sends the data directly through to the browser
103
 * DB_BINMODE_PASSTHRU sends the data directly through to the browser
104
 * when data is fetched from the database.
104
 * when data is fetched from the database.
105
 * DB_BINMODE_RETURN lets you return data as usual.
105
 * DB_BINMODE_RETURN lets you return data as usual.
106
 * DB_BINMODE_CONVERT returns data as well, only it is converted to
106
 * DB_BINMODE_CONVERT returns data as well, only it is converted to
107
 * hex format, for example the string "123" would become "313233".
107
 * hex format, for example the string "123" would become "313233".
108
 */
108
 */
109
define('DB_BINMODE_PASSTHRU', 1);
109
define('DB_BINMODE_PASSTHRU', 1);
110
define('DB_BINMODE_RETURN',   2);
110
define('DB_BINMODE_RETURN',   2);
111
define('DB_BINMODE_CONVERT',  3);
111
define('DB_BINMODE_CONVERT',  3);
112
 
112
 
113
 
113
 
114
// }}}
114
// }}}
115
// {{{ fetch modes
115
// {{{ fetch modes
116
 
116
 
117
 
117
 
118
/**
118
/**
119
 * This is a special constant that tells DB the user hasn't specified
119
 * This is a special constant that tells DB the user hasn't specified
120
 * any particular get mode, so the default should be used.
120
 * any particular get mode, so the default should be used.
121
 */
121
 */
122
define('DB_FETCHMODE_DEFAULT', 0);
122
define('DB_FETCHMODE_DEFAULT', 0);
123
 
123
 
124
/**
124
/**
125
 * Column data indexed by numbers, ordered from 0 and up
125
 * Column data indexed by numbers, ordered from 0 and up
126
 */
126
 */
127
define('DB_FETCHMODE_ORDERED', 1);
127
define('DB_FETCHMODE_ORDERED', 1);
128
 
128
 
129
/**
129
/**
130
 * Column data indexed by column names
130
 * Column data indexed by column names
131
 */
131
 */
132
define('DB_FETCHMODE_ASSOC', 2);
132
define('DB_FETCHMODE_ASSOC', 2);
133
 
133
 
134
/**
134
/**
135
 * Column data as object properties
135
 * Column data as object properties
136
 */
136
 */
137
define('DB_FETCHMODE_OBJECT', 3);
137
define('DB_FETCHMODE_OBJECT', 3);
138
 
138
 
139
/**
139
/**
140
 * For multi-dimensional results: normally the first level of arrays
140
 * For multi-dimensional results: normally the first level of arrays
141
 * is the row number, and the second level indexed by column number or name.
141
 * is the row number, and the second level indexed by column number or name.
142
 * DB_FETCHMODE_FLIPPED switches this order, so the first level of arrays
142
 * DB_FETCHMODE_FLIPPED switches this order, so the first level of arrays
143
 * is the column name, and the second level the row number.
143
 * is the column name, and the second level the row number.
144
 */
144
 */
145
define('DB_FETCHMODE_FLIPPED', 4);
145
define('DB_FETCHMODE_FLIPPED', 4);
146
 
146
 
147
/* for compatibility */
147
/* for compatibility */
148
define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED);
148
define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED);
149
define('DB_GETMODE_ASSOC',   DB_FETCHMODE_ASSOC);
149
define('DB_GETMODE_ASSOC',   DB_FETCHMODE_ASSOC);
150
define('DB_GETMODE_FLIPPED', DB_FETCHMODE_FLIPPED);
150
define('DB_GETMODE_FLIPPED', DB_FETCHMODE_FLIPPED);
151
 
151
 
152
 
152
 
153
// }}}
153
// }}}
154
// {{{ tableInfo() && autoPrepare()-related
154
// {{{ tableInfo() && autoPrepare()-related
155
 
155
 
156
 
156
 
157
/**
157
/**
158
 * these are constants for the tableInfo-function
158
 * these are constants for the tableInfo-function
159
 * they are bitwised or'ed. so if there are more constants to be defined
159
 * they are bitwised or'ed. so if there are more constants to be defined
160
 * in the future, adjust DB_TABLEINFO_FULL accordingly
160
 * in the future, adjust DB_TABLEINFO_FULL accordingly
161
 */
161
 */
162
define('DB_TABLEINFO_ORDER', 1);
162
define('DB_TABLEINFO_ORDER', 1);
163
define('DB_TABLEINFO_ORDERTABLE', 2);
163
define('DB_TABLEINFO_ORDERTABLE', 2);
164
define('DB_TABLEINFO_FULL', 3);
164
define('DB_TABLEINFO_FULL', 3);
165
 
165
 
166
/*
166
/*
167
 * Used by autoPrepare()
167
 * Used by autoPrepare()
168
 */
168
 */
169
define('DB_AUTOQUERY_INSERT', 1);
169
define('DB_AUTOQUERY_INSERT', 1);
170
define('DB_AUTOQUERY_UPDATE', 2);
170
define('DB_AUTOQUERY_UPDATE', 2);
171
 
171
 
172
 
172
 
173
// }}}
173
// }}}
174
// {{{ portability modes
174
// {{{ portability modes
175
 
175
 
176
 
176
 
177
/**
177
/**
178
 * Portability: turn off all portability features.
178
 * Portability: turn off all portability features.
179
 * @see DB_common::setOption()
179
 * @see DB_common::setOption()
180
 */
180
 */
181
define('DB_PORTABILITY_NONE', 0);
181
define('DB_PORTABILITY_NONE', 0);
182
 
182
 
183
/**
183
/**
184
 * Portability: convert names of tables and fields to lower case
184
 * Portability: convert names of tables and fields to lower case
185
 * when using the get*(), fetch*() and tableInfo() methods.
185
 * when using the get*(), fetch*() and tableInfo() methods.
186
 * @see DB_common::setOption()
186
 * @see DB_common::setOption()
187
 */
187
 */
188
define('DB_PORTABILITY_LOWERCASE', 1);
188
define('DB_PORTABILITY_LOWERCASE', 1);
189
 
189
 
190
/**
190
/**
191
 * Portability: right trim the data output by get*() and fetch*().
191
 * Portability: right trim the data output by get*() and fetch*().
192
 * @see DB_common::setOption()
192
 * @see DB_common::setOption()
193
 */
193
 */
194
define('DB_PORTABILITY_RTRIM', 2);
194
define('DB_PORTABILITY_RTRIM', 2);
195
 
195
 
196
/**
196
/**
197
 * Portability: force reporting the number of rows deleted.
197
 * Portability: force reporting the number of rows deleted.
198
 * @see DB_common::setOption()
198
 * @see DB_common::setOption()
199
 */
199
 */
200
define('DB_PORTABILITY_DELETE_COUNT', 4);
200
define('DB_PORTABILITY_DELETE_COUNT', 4);
201
 
201
 
202
/**
202
/**
203
 * Portability: enable hack that makes numRows() work in Oracle.
203
 * Portability: enable hack that makes numRows() work in Oracle.
204
 * @see DB_common::setOption()
204
 * @see DB_common::setOption()
205
 */
205
 */
206
define('DB_PORTABILITY_NUMROWS', 8);
206
define('DB_PORTABILITY_NUMROWS', 8);
207
 
207
 
208
/**
208
/**
209
 * Portability: makes certain error messages in certain drivers compatible
209
 * Portability: makes certain error messages in certain drivers compatible
210
 * with those from other DBMS's.
210
 * with those from other DBMS's.
211
 *
211
 *
212
 * + mysql, mysqli:  change unique/primary key constraints
212
 * + mysql, mysqli:  change unique/primary key constraints
213
 *   DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT
213
 *   DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT
214
 *
214
 *
215
 * + odbc(access):  MS's ODBC driver reports 'no such field' as code
215
 * + odbc(access):  MS's ODBC driver reports 'no such field' as code
216
 *   07001, which means 'too few parameters.'  When this option is on
216
 *   07001, which means 'too few parameters.'  When this option is on
217
 *   that code gets mapped to DB_ERROR_NOSUCHFIELD.
217
 *   that code gets mapped to DB_ERROR_NOSUCHFIELD.
218
 *
218
 *
219
 * @see DB_common::setOption()
219
 * @see DB_common::setOption()
220
 */
220
 */
221
define('DB_PORTABILITY_ERRORS', 16);
221
define('DB_PORTABILITY_ERRORS', 16);
222
 
222
 
223
/**
223
/**
224
 * Portability: convert null values to empty strings in data output by
224
 * Portability: convert null values to empty strings in data output by
225
 * get*() and fetch*().
225
 * get*() and fetch*().
226
 * @see DB_common::setOption()
226
 * @see DB_common::setOption()
227
 */
227
 */
228
define('DB_PORTABILITY_NULL_TO_EMPTY', 32);
228
define('DB_PORTABILITY_NULL_TO_EMPTY', 32);
229
 
229
 
230
/**
230
/**
231
 * Portability: turn on all portability features.
231
 * Portability: turn on all portability features.
232
 * @see DB_common::setOption()
232
 * @see DB_common::setOption()
233
 */
233
 */
234
define('DB_PORTABILITY_ALL', 63);
234
define('DB_PORTABILITY_ALL', 63);
235
 
235
 
236
// }}}
236
// }}}
237
 
237
 
238
 
238
 
239
// }}}
239
// }}}
240
// {{{ class DB
240
// {{{ class DB
241
 
241
 
242
/**
242
/**
243
 * The main "DB" class is simply a container class with some static
243
 * The main "DB" class is simply a container class with some static
244
 * methods for creating DB objects as well as some utility functions
244
 * methods for creating DB objects as well as some utility functions
245
 * common to all parts of DB.
245
 * common to all parts of DB.
246
 *
246
 *
247
 * The object model of DB is as follows (indentation means inheritance):
247
 * The object model of DB is as follows (indentation means inheritance):
248
 *
248
 *
249
 * DB           The main DB class.  This is simply a utility class
249
 * DB           The main DB class.  This is simply a utility class
250
 *              with some "static" methods for creating DB objects as
250
 *              with some "static" methods for creating DB objects as
251
 *              well as common utility functions for other DB classes.
251
 *              well as common utility functions for other DB classes.
252
 *
252
 *
253
 * DB_common    The base for each DB implementation.  Provides default
253
 * DB_common    The base for each DB implementation.  Provides default
254
 * |            implementations (in OO lingo virtual methods) for
254
 * |            implementations (in OO lingo virtual methods) for
255
 * |            the actual DB implementations as well as a bunch of
255
 * |            the actual DB implementations as well as a bunch of
256
 * |            query utility functions.
256
 * |            query utility functions.
257
 * |
257
 * |
258
 * +-DB_mysql   The DB implementation for MySQL.  Inherits DB_common.
258
 * +-DB_mysql   The DB implementation for MySQL.  Inherits DB_common.
259
 *              When calling DB::factory or DB::connect for MySQL
259
 *              When calling DB::factory or DB::connect for MySQL
260
 *              connections, the object returned is an instance of this
260
 *              connections, the object returned is an instance of this
261
 *              class.
261
 *              class.
262
 *
262
 *
263
 * @package  DB
263
 * @package  DB
264
 * @author   Stig Bakken <ssb@php.net>
264
 * @author   Stig Bakken <ssb@php.net>
265
 * @author   Tomas V.V.Cox <cox@idecnet.com>
265
 * @author   Tomas V.V.Cox <cox@idecnet.com>
266
 * @since    PHP 4.0
266
 * @since    PHP 4.0
267
 * @version  $Id$
267
 * @version  $Id$
268
 * @category Database
268
 * @category Database
269
 */
269
 */
270
class DB
270
class DB
271
{
271
{
272
    // {{{ &factory()
272
    // {{{ &factory()
273
 
273
 
274
    /**
274
    /**
275
     * Create a new DB object for the specified database type.
275
     * Create a new DB object for the specified database type.
276
     *
276
     *
277
     * Allows creation of a DB_<driver> object from which the object's
277
     * Allows creation of a DB_<driver> object from which the object's
278
     * methods can be utilized without actually connecting to a database.
278
     * methods can be utilized without actually connecting to a database.
279
     *
279
     *
280
     * @param string $type    database type, for example "mysql"
280
     * @param string $type    database type, for example "mysql"
281
     * @param array  $options associative array of option names and values
281
     * @param array  $options associative array of option names and values
282
     *
282
     *
283
     * @return object  a new DB object.  On error, an error object.
283
     * @return object  a new DB object.  On error, an error object.
284
     *
284
     *
285
     * @see DB_common::setOption()
285
     * @see DB_common::setOption()
286
     * @access public
286
     * @access public
287
     */
287
     */
288
    function &factory($type, $options = false)
288
    function &factory($type, $options = false)
289
    {
289
    {
290
        if (!is_array($options)) {
290
        if (!is_array($options)) {
291
            $options = array('persistent' => $options);
291
            $options = array('persistent' => $options);
292
        }
292
        }
293
 
293
 
294
        if (isset($options['debug']) && $options['debug'] >= 2) {
294
        if (isset($options['debug']) && $options['debug'] >= 2) {
295
            // expose php errors with sufficient debug level
295
            // expose php errors with sufficient debug level
296
            include_once "DB/{$type}.php";
296
            include_once "DB/{$type}.php";
297
        } else {
297
        } else {
298
            @include_once "DB/{$type}.php";
298
            @include_once "DB/{$type}.php";
299
        }
299
        }
300
 
300
 
301
        $classname = "DB_${type}";
301
        $classname = "DB_${type}";
302
 
302
 
303
        if (!class_exists($classname)) {
303
        if (!class_exists($classname)) {
304
            $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
304
            $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
305
                                    "Unable to include the DB/{$type}.php file",
305
                                    "Unable to include the DB/{$type}.php file",
306
                                    'DB_Error', true);
306
                                    'DB_Error', true);
307
            return $tmp;
307
            return $tmp;
308
        }
308
        }
309
 
309
 
310
        @$obj =& new $classname;
310
        @$obj = new $classname;
311
 
311
 
312
        foreach ($options as $option => $value) {
312
        foreach ($options as $option => $value) {
313
            $test = $obj->setOption($option, $value);
313
            $test = $obj->setOption($option, $value);
314
            if (DB::isError($test)) {
314
            if (DB::isError($test)) {
315
                return $test;
315
                return $test;
316
            }
316
            }
317
        }
317
        }
318
 
318
 
319
        return $obj;
319
        return $obj;
320
    }
320
    }
321
 
321
 
322
    // }}}
322
    // }}}
323
    // {{{ &connect()
323
    // {{{ &connect()
324
 
324
 
325
    /**
325
    /**
326
     * Create a new DB object and connect to the specified database.
326
     * Create a new DB object and connect to the specified database.
327
     *
327
     *
328
     * Example 1.
328
     * Example 1.
329
     * <code> <?php
329
     * <code> <?php
330
     * require_once 'DB.php';
330
     * require_once 'DB.php';
331
     *
331
     *
332
     * $dsn = 'mysql://user:password@host/database'
332
     * $dsn = 'mysql://user:password@host/database'
333
     * $options = array(
333
     * $options = array(
334
     *     'debug'       => 2,
334
     *     'debug'       => 2,
335
     *     'portability' => DB_PORTABILITY_ALL,
335
     *     'portability' => DB_PORTABILITY_ALL,
336
     * );
336
     * );
337
     *
337
     *
338
     * $dbh =& DB::connect($dsn, $options);
338
     * $dbh =& DB::connect($dsn, $options);
339
     * if (DB::isError($dbh)) {
339
     * if (DB::isError($dbh)) {
340
     *     die($dbh->getMessage());
340
     *     die($dbh->getMessage());
341
     * }
341
     * }
342
     * ?></code>
342
     * ?></code>
343
     *
343
     *
344
     * @param mixed $dsn      string "data source name" or an array in the
344
     * @param mixed $dsn      string "data source name" or an array in the
345
     *                        format returned by DB::parseDSN()
345
     *                        format returned by DB::parseDSN()
346
     *
346
     *
347
     * @param array $options  an associative array of option names and
347
     * @param array $options  an associative array of option names and
348
     *                        their values
348
     *                        their values
349
     *
349
     *
350
     * @return object  a newly created DB connection object, or a DB
350
     * @return object  a newly created DB connection object, or a DB
351
     *                 error object on error
351
     *                 error object on error
352
     *
352
     *
353
     * @see DB::parseDSN(), DB_common::setOption(), DB::isError()
353
     * @see DB::parseDSN(), DB_common::setOption(), DB::isError()
354
     * @access public
354
     * @access public
355
     */
355
     */
356
    function &connect($dsn, $options = array())
356
    function &connect($dsn, $options = array())
357
    {
357
    {
358
        $dsninfo = DB::parseDSN($dsn);
358
        $dsninfo = DB::parseDSN($dsn);
359
        $type = $dsninfo['phptype'];
359
        $type = $dsninfo['phptype'];
360
 
360
 
361
        if (!is_array($options)) {
361
        if (!is_array($options)) {
362
            /*
362
            /*
363
             * For backwards compatibility.  $options used to be boolean,
363
             * For backwards compatibility.  $options used to be boolean,
364
             * indicating whether the connection should be persistent.
364
             * indicating whether the connection should be persistent.
365
             */
365
             */
366
            $options = array('persistent' => $options);
366
            $options = array('persistent' => $options);
367
        }
367
        }
368
 
368
 
369
        if (isset($options['debug']) && $options['debug'] >= 2) {
369
        if (isset($options['debug']) && $options['debug'] >= 2) {
370
            // expose php errors with sufficient debug level
370
            // expose php errors with sufficient debug level
371
            include_once "DB/${type}.php";
371
            include_once "DB/${type}.php";
372
        } else {
372
        } else {
373
            @include_once "DB/${type}.php";
373
            @include_once "DB/${type}.php";
374
        }
374
        }
375
 
375
 
376
        $classname = "DB_${type}";
376
        $classname = "DB_${type}";
377
        if (!class_exists($classname)) {
377
        if (!class_exists($classname)) {
378
            $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
378
            $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
379
                                    "Unable to include the DB/{$type}.php file for `$dsn'",
379
                                    "Unable to include the DB/{$type}.php file for `$dsn'",
380
                                    'DB_Error', true);
380
                                    'DB_Error', true);
381
            return $tmp;
381
            return $tmp;
382
        }
382
        }
383
 
383
 
384
        @$obj =& new $classname;
384
        @$obj = new $classname;
385
 
385
 
386
        foreach ($options as $option => $value) {
386
        foreach ($options as $option => $value) {
387
            $test = $obj->setOption($option, $value);
387
            $test = $obj->setOption($option, $value);
388
            if (DB::isError($test)) {
388
            if (DB::isError($test)) {
389
                return $test;
389
                return $test;
390
            }
390
            }
391
        }
391
        }
392
 
392
 
393
        $err = $obj->connect($dsninfo, $obj->getOption('persistent'));
393
        $err = $obj->connect($dsninfo, $obj->getOption('persistent'));
394
        if (DB::isError($err)) {
394
        if (DB::isError($err)) {
395
            $err->addUserInfo($dsn);
395
            $err->addUserInfo($dsn);
396
            return $err;
396
            return $err;
397
        }
397
        }
398
 
398
 
399
        return $obj;
399
        return $obj;
400
    }
400
    }
401
 
401
 
402
    // }}}
402
    // }}}
403
    // {{{ apiVersion()
403
    // {{{ apiVersion()
404
 
404
 
405
    /**
405
    /**
406
     * Return the DB API version
406
     * Return the DB API version
407
     *
407
     *
408
     * @return int the DB API version number
408
     * @return int the DB API version number
409
     *
409
     *
410
     * @access public
410
     * @access public
411
     */
411
     */
412
    function apiVersion()
412
    function apiVersion()
413
    {
413
    {
414
        return 2;
414
        return 2;
415
    }
415
    }
416
 
416
 
417
    // }}}
417
    // }}}
418
    // {{{ isError()
418
    // {{{ isError()
419
 
419
 
420
    /**
420
    /**
421
     * Tell whether a result code from a DB method is an error
421
     * Tell whether a result code from a DB method is an error
422
     *
422
     *
423
     * @param int $value result code
423
     * @param int $value result code
424
     *
424
     *
425
     * @return bool whether $value is an error
425
     * @return bool whether $value is an error
426
     *
426
     *
427
     * @access public
427
     * @access public
428
     */
428
     */
429
    function isError($value)
429
    function isError($value)
430
    {
430
    {
431
        return is_a($value, 'DB_Error');
431
        return is_a($value, 'DB_Error');
432
    }
432
    }
433
 
433
 
434
    // }}}
434
    // }}}
435
    // {{{ isConnection()
435
    // {{{ isConnection()
436
 
436
 
437
    /**
437
    /**
438
     * Tell whether a value is a DB connection
438
     * Tell whether a value is a DB connection
439
     *
439
     *
440
     * @param mixed $value value to test
440
     * @param mixed $value value to test
441
     *
441
     *
442
     * @return bool whether $value is a DB connection
442
     * @return bool whether $value is a DB connection
443
     *
443
     *
444
     * @access public
444
     * @access public
445
     */
445
     */
446
    function isConnection($value)
446
    function isConnection($value)
447
    {
447
    {
448
        return (is_object($value) &&
448
        return (is_object($value) &&
449
                is_subclass_of($value, 'db_common') &&
449
                is_subclass_of($value, 'db_common') &&
450
                method_exists($value, 'simpleQuery'));
450
                method_exists($value, 'simpleQuery'));
451
    }
451
    }
452
 
452
 
453
    // }}}
453
    // }}}
454
    // {{{ isManip()
454
    // {{{ isManip()
455
 
455
 
456
    /**
456
    /**
457
     * Tell whether a query is a data manipulation query (insert,
457
     * Tell whether a query is a data manipulation query (insert,
458
     * update or delete) or a data definition query (create, drop,
458
     * update or delete) or a data definition query (create, drop,
459
     * alter, grant, revoke).
459
     * alter, grant, revoke).
460
     *
460
     *
461
     * @access public
461
     * @access public
462
     *
462
     *
463
     * @param string $query the query
463
     * @param string $query the query
464
     *
464
     *
465
     * @return boolean whether $query is a data manipulation query
465
     * @return boolean whether $query is a data manipulation query
466
     */
466
     */
467
    function isManip($query)
467
    function isManip($query)
468
    {
468
    {
469
        $manips = 'INSERT|UPDATE|DELETE|LOAD DATA|'.'REPLACE|CREATE|DROP|'.
469
        $manips = 'INSERT|UPDATE|DELETE|LOAD DATA|'.'REPLACE|CREATE|DROP|'.
470
                  'ALTER|GRANT|REVOKE|'.'LOCK|UNLOCK';
470
                  'ALTER|GRANT|REVOKE|'.'LOCK|UNLOCK';
471
        if (preg_match('/^\s*"?('.$manips.')\s+/i', $query)) {
471
        if (preg_match('/^\s*"?('.$manips.')\s+/i', $query)) {
472
            return true;
472
            return true;
473
        }
473
        }
474
        return false;
474
        return false;
475
    }
475
    }
476
 
476
 
477
    // }}}
477
    // }}}
478
    // {{{ errorMessage()
478
    // {{{ errorMessage()
479
 
479
 
480
    /**
480
    /**
481
     * Return a textual error message for a DB error code
481
     * Return a textual error message for a DB error code
482
     *
482
     *
483
     * @param integer $value error code
483
     * @param integer $value error code
484
     *
484
     *
485
     * @return string error message, or false if the error code was
485
     * @return string error message, or false if the error code was
486
     * not recognized
486
     * not recognized
487
     */
487
     */
488
    function errorMessage($value)
488
    function errorMessage($value)
489
    {
489
    {
490
        static $errorMessages;
490
        static $errorMessages;
491
        if (!isset($errorMessages)) {
491
        if (!isset($errorMessages)) {
492
            $errorMessages = array(
492
            $errorMessages = array(
493
                DB_ERROR                    => 'unknown error',
493
                DB_ERROR                    => 'unknown error',
494
                DB_ERROR_ALREADY_EXISTS     => 'already exists',
494
                DB_ERROR_ALREADY_EXISTS     => 'already exists',
495
                DB_ERROR_CANNOT_CREATE      => 'can not create',
495
                DB_ERROR_CANNOT_CREATE      => 'can not create',
496
                DB_ERROR_CANNOT_DELETE      => 'can not delete',
496
                DB_ERROR_CANNOT_DELETE      => 'can not delete',
497
                DB_ERROR_CANNOT_DROP        => 'can not drop',
497
                DB_ERROR_CANNOT_DROP        => 'can not drop',
498
                DB_ERROR_CONSTRAINT         => 'constraint violation',
498
                DB_ERROR_CONSTRAINT         => 'constraint violation',
499
                DB_ERROR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint',
499
                DB_ERROR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint',
500
                DB_ERROR_DIVZERO            => 'division by zero',
500
                DB_ERROR_DIVZERO            => 'division by zero',
501
                DB_ERROR_INVALID            => 'invalid',
501
                DB_ERROR_INVALID            => 'invalid',
502
                DB_ERROR_INVALID_DATE       => 'invalid date or time',
502
                DB_ERROR_INVALID_DATE       => 'invalid date or time',
503
                DB_ERROR_INVALID_NUMBER     => 'invalid number',
503
                DB_ERROR_INVALID_NUMBER     => 'invalid number',
504
                DB_ERROR_MISMATCH           => 'mismatch',
504
                DB_ERROR_MISMATCH           => 'mismatch',
505
                DB_ERROR_NODBSELECTED       => 'no database selected',
505
                DB_ERROR_NODBSELECTED       => 'no database selected',
506
                DB_ERROR_NOSUCHFIELD        => 'no such field',
506
                DB_ERROR_NOSUCHFIELD        => 'no such field',
507
                DB_ERROR_NOSUCHTABLE        => 'no such table',
507
                DB_ERROR_NOSUCHTABLE        => 'no such table',
508
                DB_ERROR_NOT_CAPABLE        => 'DB backend not capable',
508
                DB_ERROR_NOT_CAPABLE        => 'DB backend not capable',
509
                DB_ERROR_NOT_FOUND          => 'not found',
509
                DB_ERROR_NOT_FOUND          => 'not found',
510
                DB_ERROR_NOT_LOCKED         => 'not locked',
510
                DB_ERROR_NOT_LOCKED         => 'not locked',
511
                DB_ERROR_SYNTAX             => 'syntax error',
511
                DB_ERROR_SYNTAX             => 'syntax error',
512
                DB_ERROR_UNSUPPORTED        => 'not supported',
512
                DB_ERROR_UNSUPPORTED        => 'not supported',
513
                DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
513
                DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
514
                DB_ERROR_INVALID_DSN        => 'invalid DSN',
514
                DB_ERROR_INVALID_DSN        => 'invalid DSN',
515
                DB_ERROR_CONNECT_FAILED     => 'connect failed',
515
                DB_ERROR_CONNECT_FAILED     => 'connect failed',
516
                DB_OK                       => 'no error',
516
                DB_OK                       => 'no error',
517
                DB_ERROR_NEED_MORE_DATA     => 'insufficient data supplied',
517
                DB_ERROR_NEED_MORE_DATA     => 'insufficient data supplied',
518
                DB_ERROR_EXTENSION_NOT_FOUND=> 'extension not found',
518
                DB_ERROR_EXTENSION_NOT_FOUND=> 'extension not found',
519
                DB_ERROR_NOSUCHDB           => 'no such database',
519
                DB_ERROR_NOSUCHDB           => 'no such database',
520
                DB_ERROR_ACCESS_VIOLATION   => 'insufficient permissions',
520
                DB_ERROR_ACCESS_VIOLATION   => 'insufficient permissions',
521
                DB_ERROR_TRUNCATED          => 'truncated'
521
                DB_ERROR_TRUNCATED          => 'truncated'
522
            );
522
            );
523
        }
523
        }
524
 
524
 
525
        if (DB::isError($value)) {
525
        if (DB::isError($value)) {
526
            $value = $value->getCode();
526
            $value = $value->getCode();
527
        }
527
        }
528
 
528
 
529
        return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[DB_ERROR];
529
        return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[DB_ERROR];
530
    }
530
    }
531
 
531
 
532
    // }}}
532
    // }}}
533
    // {{{ parseDSN()
533
    // {{{ parseDSN()
534
 
534
 
535
    /**
535
    /**
536
     * Parse a data source name.
536
     * Parse a data source name.
537
     *
537
     *
538
     * Additional keys can be added by appending a URI query string to the
538
     * Additional keys can be added by appending a URI query string to the
539
     * end of the DSN.
539
     * end of the DSN.
540
     *
540
     *
541
     * The format of the supplied DSN is in its fullest form:
541
     * The format of the supplied DSN is in its fullest form:
542
     * <code>
542
     * <code>
543
     *  phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
543
     *  phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
544
     * </code>
544
     * </code>
545
     *
545
     *
546
     * Most variations are allowed:
546
     * Most variations are allowed:
547
     * <code>
547
     * <code>
548
     *  phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
548
     *  phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
549
     *  phptype://username:password@hostspec/database_name
549
     *  phptype://username:password@hostspec/database_name
550
     *  phptype://username:password@hostspec
550
     *  phptype://username:password@hostspec
551
     *  phptype://username@hostspec
551
     *  phptype://username@hostspec
552
     *  phptype://hostspec/database
552
     *  phptype://hostspec/database
553
     *  phptype://hostspec
553
     *  phptype://hostspec
554
     *  phptype(dbsyntax)
554
     *  phptype(dbsyntax)
555
     *  phptype
555
     *  phptype
556
     * </code>
556
     * </code>
557
     *
557
     *
558
     * @param string $dsn Data Source Name to be parsed
558
     * @param string $dsn Data Source Name to be parsed
559
     *
559
     *
560
     * @return array an associative array with the following keys:
560
     * @return array an associative array with the following keys:
561
     *  + phptype:  Database backend used in PHP (mysql, odbc etc.)
561
     *  + phptype:  Database backend used in PHP (mysql, odbc etc.)
562
     *  + dbsyntax: Database used with regards to SQL syntax etc.
562
     *  + dbsyntax: Database used with regards to SQL syntax etc.
563
     *  + protocol: Communication protocol to use (tcp, unix etc.)
563
     *  + protocol: Communication protocol to use (tcp, unix etc.)
564
     *  + hostspec: Host specification (hostname[:port])
564
     *  + hostspec: Host specification (hostname[:port])
565
     *  + database: Database to use on the DBMS server
565
     *  + database: Database to use on the DBMS server
566
     *  + username: User name for login
566
     *  + username: User name for login
567
     *  + password: Password for login
567
     *  + password: Password for login
568
     *
568
     *
569
     * @author Tomas V.V.Cox <cox@idecnet.com>
569
     * @author Tomas V.V.Cox <cox@idecnet.com>
570
     */
570
     */
571
    function parseDSN($dsn)
571
    function parseDSN($dsn)
572
    {
572
    {
573
        $parsed = array(
573
        $parsed = array(
574
            'phptype'  => false,
574
            'phptype'  => false,
575
            'dbsyntax' => false,
575
            'dbsyntax' => false,
576
            'username' => false,
576
            'username' => false,
577
            'password' => false,
577
            'password' => false,
578
            'protocol' => false,
578
            'protocol' => false,
579
            'hostspec' => false,
579
            'hostspec' => false,
580
            'port'     => false,
580
            'port'     => false,
581
            'socket'   => false,
581
            'socket'   => false,
582
            'database' => false,
582
            'database' => false,
583
        );
583
        );
584
 
584
 
585
        if (is_array($dsn)) {
585
        if (is_array($dsn)) {
586
            $dsn = array_merge($parsed, $dsn);
586
            $dsn = array_merge($parsed, $dsn);
587
            if (!$dsn['dbsyntax']) {
587
            if (!$dsn['dbsyntax']) {
588
                $dsn['dbsyntax'] = $dsn['phptype'];
588
                $dsn['dbsyntax'] = $dsn['phptype'];
589
            }
589
            }
590
            return $dsn;
590
            return $dsn;
591
        }
591
        }
592
 
592
 
593
        // Find phptype and dbsyntax
593
        // Find phptype and dbsyntax
594
        if (($pos = strpos($dsn, '://')) !== false) {
594
        if (($pos = strpos($dsn, '://')) !== false) {
595
            $str = substr($dsn, 0, $pos);
595
            $str = substr($dsn, 0, $pos);
596
            $dsn = substr($dsn, $pos + 3);
596
            $dsn = substr($dsn, $pos + 3);
597
        } else {
597
        } else {
598
            $str = $dsn;
598
            $str = $dsn;
599
            $dsn = null;
599
            $dsn = null;
600
        }
600
        }
601
 
601
 
602
        // Get phptype and dbsyntax
602
        // Get phptype and dbsyntax
603
        // $str => phptype(dbsyntax)
603
        // $str => phptype(dbsyntax)
604
        if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
604
        if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
605
            $parsed['phptype']  = $arr[1];
605
            $parsed['phptype']  = $arr[1];
606
            $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
606
            $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
607
        } else {
607
        } else {
608
            $parsed['phptype']  = $str;
608
            $parsed['phptype']  = $str;
609
            $parsed['dbsyntax'] = $str;
609
            $parsed['dbsyntax'] = $str;
610
        }
610
        }
611
 
611
 
612
        if (!count($dsn)) {
612
        if (!count($dsn)) {
613
            return $parsed;
613
            return $parsed;
614
        }
614
        }
615
 
615
 
616
        // Get (if found): username and password
616
        // Get (if found): username and password
617
        // $dsn => username:password@protocol+hostspec/database
617
        // $dsn => username:password@protocol+hostspec/database
618
        if (($at = strrpos($dsn,'@')) !== false) {
618
        if (($at = strrpos($dsn,'@')) !== false) {
619
            $str = substr($dsn, 0, $at);
619
            $str = substr($dsn, 0, $at);
620
            $dsn = substr($dsn, $at + 1);
620
            $dsn = substr($dsn, $at + 1);
621
            if (($pos = strpos($str, ':')) !== false) {
621
            if (($pos = strpos($str, ':')) !== false) {
622
                $parsed['username'] = rawurldecode(substr($str, 0, $pos));
622
                $parsed['username'] = rawurldecode(substr($str, 0, $pos));
623
                $parsed['password'] = rawurldecode(substr($str, $pos + 1));
623
                $parsed['password'] = rawurldecode(substr($str, $pos + 1));
624
            } else {
624
            } else {
625
                $parsed['username'] = rawurldecode($str);
625
                $parsed['username'] = rawurldecode($str);
626
            }
626
            }
627
        }
627
        }
628
 
628
 
629
        // Find protocol and hostspec
629
        // Find protocol and hostspec
630
 
630
 
631
        // $dsn => proto(proto_opts)/database
631
        // $dsn => proto(proto_opts)/database
632
        if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
632
        if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
633
            $proto       = $match[1];
633
            $proto       = $match[1];
634
            $proto_opts  = $match[2] ? $match[2] : false;
634
            $proto_opts  = $match[2] ? $match[2] : false;
635
            $dsn         = $match[3];
635
            $dsn         = $match[3];
636
 
636
 
637
        // $dsn => protocol+hostspec/database (old format)
637
        // $dsn => protocol+hostspec/database (old format)
638
        } else {
638
        } else {
639
            if (strpos($dsn, '+') !== false) {
639
            if (strpos($dsn, '+') !== false) {
640
                list($proto, $dsn) = explode('+', $dsn, 2);
640
                list($proto, $dsn) = explode('+', $dsn, 2);
641
            }
641
            }
642
            if (strpos($dsn, '/') !== false) {
642
            if (strpos($dsn, '/') !== false) {
643
                list($proto_opts, $dsn) = explode('/', $dsn, 2);
643
                list($proto_opts, $dsn) = explode('/', $dsn, 2);
644
            } else {
644
            } else {
645
                $proto_opts = $dsn;
645
                $proto_opts = $dsn;
646
                $dsn = null;
646
                $dsn = null;
647
            }
647
            }
648
        }
648
        }
649
 
649
 
650
        // process the different protocol options
650
        // process the different protocol options
651
        $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
651
        $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
652
        $proto_opts = rawurldecode($proto_opts);
652
        $proto_opts = rawurldecode($proto_opts);
653
        if ($parsed['protocol'] == 'tcp') {
653
        if ($parsed['protocol'] == 'tcp') {
654
            if (strpos($proto_opts, ':') !== false) {
654
            if (strpos($proto_opts, ':') !== false) {
655
                list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);
655
                list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);
656
            } else {
656
            } else {
657
                $parsed['hostspec'] = $proto_opts;
657
                $parsed['hostspec'] = $proto_opts;
658
            }
658
            }
659
        } elseif ($parsed['protocol'] == 'unix') {
659
        } elseif ($parsed['protocol'] == 'unix') {
660
            $parsed['socket'] = $proto_opts;
660
            $parsed['socket'] = $proto_opts;
661
        }
661
        }
662
 
662
 
663
        // Get dabase if any
663
        // Get dabase if any
664
        // $dsn => database
664
        // $dsn => database
665
        if ($dsn) {
665
        if ($dsn) {
666
            // /database
666
            // /database
667
            if (($pos = strpos($dsn, '?')) === false) {
667
            if (($pos = strpos($dsn, '?')) === false) {
668
                $parsed['database'] = $dsn;
668
                $parsed['database'] = $dsn;
669
            // /database?param1=value1&param2=value2
669
            // /database?param1=value1&param2=value2
670
            } else {
670
            } else {
671
                $parsed['database'] = substr($dsn, 0, $pos);
671
                $parsed['database'] = substr($dsn, 0, $pos);
672
                $dsn = substr($dsn, $pos + 1);
672
                $dsn = substr($dsn, $pos + 1);
673
                if (strpos($dsn, '&') !== false) {
673
                if (strpos($dsn, '&') !== false) {
674
                    $opts = explode('&', $dsn);
674
                    $opts = explode('&', $dsn);
675
                } else { // database?param1=value1
675
                } else { // database?param1=value1
676
                    $opts = array($dsn);
676
                    $opts = array($dsn);
677
                }
677
                }
678
                foreach ($opts as $opt) {
678
                foreach ($opts as $opt) {
679
                    list($key, $value) = explode('=', $opt);
679
                    list($key, $value) = explode('=', $opt);
680
                    if (!isset($parsed[$key])) {
680
                    if (!isset($parsed[$key])) {
681
                        // don't allow params overwrite
681
                        // don't allow params overwrite
682
                        $parsed[$key] = rawurldecode($value);
682
                        $parsed[$key] = rawurldecode($value);
683
                    }
683
                    }
684
                }
684
                }
685
            }
685
            }
686
        }
686
        }
687
 
687
 
688
        return $parsed;
688
        return $parsed;
689
    }
689
    }
690
 
690
 
691
    // }}}
691
    // }}}
692
    // {{{ assertExtension()
692
    // {{{ assertExtension()
693
 
693
 
694
    /**
694
    /**
695
     * Load a PHP database extension if it is not loaded already.
695
     * Load a PHP database extension if it is not loaded already.
696
     *
696
     *
697
     * @access public
697
     * @access public
698
     *
698
     *
699
     * @param string $name the base name of the extension (without the .so or
699
     * @param string $name the base name of the extension (without the .so or
700
     *                     .dll suffix)
700
     *                     .dll suffix)
701
     *
701
     *
702
     * @return boolean true if the extension was already or successfully
702
     * @return boolean true if the extension was already or successfully
703
     *                 loaded, false if it could not be loaded
703
     *                 loaded, false if it could not be loaded
704
     */
704
     */
705
    function assertExtension($name)
705
    function assertExtension($name)
706
    {
706
    {
707
        if (!extension_loaded($name)) {
707
        if (!extension_loaded($name)) {
708
            $dlext = OS_WINDOWS ? '.dll' : '.so';
708
            $dlext = OS_WINDOWS ? '.dll' : '.so';
709
            $dlprefix = OS_WINDOWS ? 'php_' : '';
709
            $dlprefix = OS_WINDOWS ? 'php_' : '';
710
            @dl($dlprefix . $name . $dlext);
710
            @dl($dlprefix . $name . $dlext);
711
            return extension_loaded($name);
711
            return extension_loaded($name);
712
        }
712
        }
713
        return true;
713
        return true;
714
    }
714
    }
715
    // }}}
715
    // }}}
716
}
716
}
717
 
717
 
718
// }}}
718
// }}}
719
// {{{ class DB_Error
719
// {{{ class DB_Error
720
 
720
 
721
/**
721
/**
722
 * DB_Error implements a class for reporting portable database error
722
 * DB_Error implements a class for reporting portable database error
723
 * messages.
723
 * messages.
724
 *
724
 *
725
 * @package  DB
725
 * @package  DB
726
 * @author Stig Bakken <ssb@php.net>
726
 * @author Stig Bakken <ssb@php.net>
727
 */
727
 */
728
class DB_Error extends PEAR_Error
728
class DB_Error extends PEAR_Error
729
{
729
{
730
    // {{{ constructor
730
    // {{{ constructor
731
 
731
 
732
    /**
732
    /**
733
     * DB_Error constructor.
733
     * DB_Error constructor.
734
     *
734
     *
735
     * @param mixed   $code   DB error code, or string with error message.
735
     * @param mixed   $code   DB error code, or string with error message.
736
     * @param integer $mode   what "error mode" to operate in
736
     * @param integer $mode   what "error mode" to operate in
737
     * @param integer $level  what error level to use for $mode & PEAR_ERROR_TRIGGER
737
     * @param integer $level  what error level to use for $mode & PEAR_ERROR_TRIGGER
738
     * @param mixed   $debuginfo  additional debug info, such as the last query
738
     * @param mixed   $debuginfo  additional debug info, such as the last query
739
     *
739
     *
740
     * @access public
740
     * @access public
741
     *
741
     *
742
     * @see PEAR_Error
742
     * @see PEAR_Error
743
     */
743
     */
744
    function DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
744
    function DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
745
              $level = E_USER_NOTICE, $debuginfo = null)
745
              $level = E_USER_NOTICE, $debuginfo = null)
746
    {
746
    {
747
        if (is_int($code)) {
747
        if (is_int($code)) {
748
            $this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code, $mode, $level, $debuginfo);
748
            $this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code, $mode, $level, $debuginfo);
749
        } else {
749
        } else {
750
            $this->PEAR_Error("DB Error: $code", DB_ERROR, $mode, $level, $debuginfo);
750
            $this->PEAR_Error("DB Error: $code", DB_ERROR, $mode, $level, $debuginfo);
751
        }
751
        }
752
    }
752
    }
753
    // }}}
753
    // }}}
754
}
754
}
755
 
755
 
756
// }}}
756
// }}}
757
// {{{ class DB_result
757
// {{{ class DB_result
758
 
758
 
759
/**
759
/**
760
 * This class implements a wrapper for a DB result set.
760
 * This class implements a wrapper for a DB result set.
761
 * A new instance of this class will be returned by the DB implementation
761
 * A new instance of this class will be returned by the DB implementation
762
 * after processing a query that returns data.
762
 * after processing a query that returns data.
763
 *
763
 *
764
 * @package  DB
764
 * @package  DB
765
 * @author Stig Bakken <ssb@php.net>
765
 * @author Stig Bakken <ssb@php.net>
766
 */
766
 */
767
class DB_result
767
class DB_result
768
{
768
{
769
    // {{{ properties
769
    // {{{ properties
770
 
770
 
771
    var $dbh;
771
    var $dbh;
772
    var $result;
772
    var $result;
773
    var $row_counter = null;
773
    var $row_counter = null;
774
 
774
 
775
    /**
775
    /**
776
     * for limit queries, the row to start fetching
776
     * for limit queries, the row to start fetching
777
     * @var integer
777
     * @var integer
778
     */
778
     */
779
    var $limit_from  = null;
779
    var $limit_from  = null;
780
 
780
 
781
    /**
781
    /**
782
     * for limit queries, the number of rows to fetch
782
     * for limit queries, the number of rows to fetch
783
     * @var integer
783
     * @var integer
784
     */
784
     */
785
    var $limit_count = null;
785
    var $limit_count = null;
786
 
786
 
787
    // }}}
787
    // }}}
788
    // {{{ constructor
788
    // {{{ constructor
789
 
789
 
790
    /**
790
    /**
791
     * DB_result constructor.
791
     * DB_result constructor.
792
     * @param resource &$dbh   DB object reference
792
     * @param resource &$dbh   DB object reference
793
     * @param resource $result  result resource id
793
     * @param resource $result  result resource id
794
     * @param array    $options assoc array with optional result options
794
     * @param array    $options assoc array with optional result options
795
     */
795
     */
796
    function DB_result(&$dbh, $result, $options = array())
796
    function DB_result(&$dbh, $result, $options = array())
797
    {
797
    {
798
        $this->dbh = &$dbh;
798
        $this->dbh = &$dbh;
799
        $this->result = $result;
799
        $this->result = $result;
800
        foreach ($options as $key => $value) {
800
        foreach ($options as $key => $value) {
801
            $this->setOption($key, $value);
801
            $this->setOption($key, $value);
802
        }
802
        }
803
        $this->limit_type  = $dbh->features['limit'];
803
        $this->limit_type  = $dbh->features['limit'];
804
        $this->autofree    = $dbh->options['autofree'];
804
        $this->autofree    = $dbh->options['autofree'];
805
        $this->fetchmode   = $dbh->fetchmode;
805
        $this->fetchmode   = $dbh->fetchmode;
806
        $this->fetchmode_object_class = $dbh->fetchmode_object_class;
806
        $this->fetchmode_object_class = $dbh->fetchmode_object_class;
807
    }
807
    }
808
 
808
 
809
    function setOption($key, $value = null)
809
    function setOption($key, $value = null)
810
    {
810
    {
811
        switch ($key) {
811
        switch ($key) {
812
            case 'limit_from':
812
            case 'limit_from':
813
                $this->limit_from = $value; break;
813
                $this->limit_from = $value; break;
814
            case 'limit_count':
814
            case 'limit_count':
815
                $this->limit_count = $value; break;
815
                $this->limit_count = $value; break;
816
        }
816
        }
817
    }
817
    }
818
 
818
 
819
    // }}}
819
    // }}}
820
    // {{{ fetchRow()
820
    // {{{ fetchRow()
821
 
821
 
822
    /**
822
    /**
823
     * Fetch a row of data and return it by reference into an array.
823
     * Fetch a row of data and return it by reference into an array.
824
     *
824
     *
825
     * The type of array returned can be controlled either by setting this
825
     * The type of array returned can be controlled either by setting this
826
     * method's <var>$fetchmode</var> parameter or by changing the default
826
     * method's <var>$fetchmode</var> parameter or by changing the default
827
     * fetch mode setFetchMode() before calling this method.
827
     * fetch mode setFetchMode() before calling this method.
828
     *
828
     *
829
     * There are two options for standardizing the information returned
829
     * There are two options for standardizing the information returned
830
     * from databases, ensuring their values are consistent when changing
830
     * from databases, ensuring their values are consistent when changing
831
     * DBMS's.  These portability options can be turned on when creating a
831
     * DBMS's.  These portability options can be turned on when creating a
832
     * new DB object or by using setOption().
832
     * new DB object or by using setOption().
833
     *
833
     *
834
     *   + <samp>DB_PORTABILITY_LOWERCASE</samp>
834
     *   + <samp>DB_PORTABILITY_LOWERCASE</samp>
835
     *     convert names of fields to lower case
835
     *     convert names of fields to lower case
836
     *
836
     *
837
     *   + <samp>DB_PORTABILITY_RTRIM</samp>
837
     *   + <samp>DB_PORTABILITY_RTRIM</samp>
838
     *     right trim the data
838
     *     right trim the data
839
     *
839
     *
840
     * @param int $fetchmode  how the resulting array should be indexed
840
     * @param int $fetchmode  how the resulting array should be indexed
841
     * @param int $rownum     the row number to fetch
841
     * @param int $rownum     the row number to fetch
842
     *
842
     *
843
     * @return array  a row of data, null on no more rows or PEAR_Error
843
     * @return array  a row of data, null on no more rows or PEAR_Error
844
     *                object on error
844
     *                object on error
845
     *
845
     *
846
     * @see DB_common::setOption(), DB_common::setFetchMode()
846
     * @see DB_common::setOption(), DB_common::setFetchMode()
847
     * @access public
847
     * @access public
848
     */
848
     */
849
    function &fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
849
    function &fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
850
    {
850
    {
851
        if ($fetchmode === DB_FETCHMODE_DEFAULT) {
851
        if ($fetchmode === DB_FETCHMODE_DEFAULT) {
852
            $fetchmode = $this->fetchmode;
852
            $fetchmode = $this->fetchmode;
853
        }
853
        }
854
        if ($fetchmode === DB_FETCHMODE_OBJECT) {
854
        if ($fetchmode === DB_FETCHMODE_OBJECT) {
855
            $fetchmode = DB_FETCHMODE_ASSOC;
855
            $fetchmode = DB_FETCHMODE_ASSOC;
856
            $object_class = $this->fetchmode_object_class;
856
            $object_class = $this->fetchmode_object_class;
857
        }
857
        }
858
        if ($this->limit_from !== null) {
858
        if ($this->limit_from !== null) {
859
            if ($this->row_counter === null) {
859
            if ($this->row_counter === null) {
860
                $this->row_counter = $this->limit_from;
860
                $this->row_counter = $this->limit_from;
861
                // Skip rows
861
                // Skip rows
862
                if ($this->limit_type == false) {
862
                if ($this->limit_type == false) {
863
                    $i = 0;
863
                    $i = 0;
864
                    while ($i++ < $this->limit_from) {
864
                    while ($i++ < $this->limit_from) {
865
                        $this->dbh->fetchInto($this->result, $arr, $fetchmode);
865
                        $this->dbh->fetchInto($this->result, $arr, $fetchmode);
866
                    }
866
                    }
867
                }
867
                }
868
            }
868
            }
869
            if ($this->row_counter >= (
869
            if ($this->row_counter >= (
870
                    $this->limit_from + $this->limit_count))
870
                    $this->limit_from + $this->limit_count))
871
            {
871
            {
872
                if ($this->autofree) {
872
                if ($this->autofree) {
873
                    $this->free();
873
                    $this->free();
874
                }
874
                }
875
                $tmp = null;
875
                $tmp = null;
876
                return $tmp;
876
                return $tmp;
877
            }
877
            }
878
            if ($this->limit_type == 'emulate') {
878
            if ($this->limit_type == 'emulate') {
879
                $rownum = $this->row_counter;
879
                $rownum = $this->row_counter;
880
            }
880
            }
881
            $this->row_counter++;
881
            $this->row_counter++;
882
        }
882
        }
883
        $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
883
        $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
884
        if ($res === DB_OK) {
884
        if ($res === DB_OK) {
885
            if (isset($object_class)) {
885
            if (isset($object_class)) {
886
                // default mode specified in DB_common::fetchmode_object_class property
886
                // default mode specified in DB_common::fetchmode_object_class property
887
                if ($object_class == 'stdClass') {
887
                if ($object_class == 'stdClass') {
888
                    $arr = (object) $arr;
888
                    $arr = (object) $arr;
889
                } else {
889
                } else {
890
                    $arr = &new $object_class($arr);
890
                    $arr = new $object_class($arr);
891
                }
891
                }
892
            }
892
            }
893
            return $arr;
893
            return $arr;
894
        }
894
        }
895
        if ($res == null && $this->autofree) {
895
        if ($res == null && $this->autofree) {
896
            $this->free();
896
            $this->free();
897
        }
897
        }
898
        return $res;
898
        return $res;
899
    }
899
    }
900
 
900
 
901
    // }}}
901
    // }}}
902
    // {{{ fetchInto()
902
    // {{{ fetchInto()
903
 
903
 
904
    /**
904
    /**
905
     * Fetch a row of data into an array which is passed by reference.
905
     * Fetch a row of data into an array which is passed by reference.
906
     *
906
     *
907
     * The type of array returned can be controlled either by setting this
907
     * The type of array returned can be controlled either by setting this
908
     * method's <var>$fetchmode</var> parameter or by changing the default
908
     * method's <var>$fetchmode</var> parameter or by changing the default
909
     * fetch mode setFetchMode() before calling this method.
909
     * fetch mode setFetchMode() before calling this method.
910
     *
910
     *
911
     * There are two options for standardizing the information returned
911
     * There are two options for standardizing the information returned
912
     * from databases, ensuring their values are consistent when changing
912
     * from databases, ensuring their values are consistent when changing
913
     * DBMS's.  These portability options can be turned on when creating a
913
     * DBMS's.  These portability options can be turned on when creating a
914
     * new DB object or by using setOption().
914
     * new DB object or by using setOption().
915
     *
915
     *
916
     *   + <samp>DB_PORTABILITY_LOWERCASE</samp>
916
     *   + <samp>DB_PORTABILITY_LOWERCASE</samp>
917
     *     convert names of fields to lower case
917
     *     convert names of fields to lower case
918
     *
918
     *
919
     *   + <samp>DB_PORTABILITY_RTRIM</samp>
919
     *   + <samp>DB_PORTABILITY_RTRIM</samp>
920
     *     right trim the data
920
     *     right trim the data
921
     *
921
     *
922
     * @param array &$arr       (reference) array where data from the row
922
     * @param array &$arr       (reference) array where data from the row
923
     *                          should be placed
923
     *                          should be placed
924
     * @param int   $fetchmode  how the resulting array should be indexed
924
     * @param int   $fetchmode  how the resulting array should be indexed
925
     * @param int   $rownum     the row number to fetch
925
     * @param int   $rownum     the row number to fetch
926
     *
926
     *
927
     * @return mixed  DB_OK on success, null on no more rows or
927
     * @return mixed  DB_OK on success, null on no more rows or
928
     *                a DB_Error object on error
928
     *                a DB_Error object on error
929
     *
929
     *
930
     * @see DB_common::setOption(), DB_common::setFetchMode()
930
     * @see DB_common::setOption(), DB_common::setFetchMode()
931
     * @access public
931
     * @access public
932
     */
932
     */
933
    function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
933
    function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
934
    {
934
    {
935
        if ($fetchmode === DB_FETCHMODE_DEFAULT) {
935
        if ($fetchmode === DB_FETCHMODE_DEFAULT) {
936
            $fetchmode = $this->fetchmode;
936
            $fetchmode = $this->fetchmode;
937
        }
937
        }
938
        if ($fetchmode === DB_FETCHMODE_OBJECT) {
938
        if ($fetchmode === DB_FETCHMODE_OBJECT) {
939
            $fetchmode = DB_FETCHMODE_ASSOC;
939
            $fetchmode = DB_FETCHMODE_ASSOC;
940
            $object_class = $this->fetchmode_object_class;
940
            $object_class = $this->fetchmode_object_class;
941
        }
941
        }
942
        if ($this->limit_from !== null) {
942
        if ($this->limit_from !== null) {
943
            if ($this->row_counter === null) {
943
            if ($this->row_counter === null) {
944
                $this->row_counter = $this->limit_from;
944
                $this->row_counter = $this->limit_from;
945
                // Skip rows
945
                // Skip rows
946
                if ($this->limit_type == false) {
946
                if ($this->limit_type == false) {
947
                    $i = 0;
947
                    $i = 0;
948
                    while ($i++ < $this->limit_from) {
948
                    while ($i++ < $this->limit_from) {
949
                        $this->dbh->fetchInto($this->result, $arr, $fetchmode);
949
                        $this->dbh->fetchInto($this->result, $arr, $fetchmode);
950
                    }
950
                    }
951
                }
951
                }
952
            }
952
            }
953
            if ($this->row_counter >= (
953
            if ($this->row_counter >= (
954
                    $this->limit_from + $this->limit_count))
954
                    $this->limit_from + $this->limit_count))
955
            {
955
            {
956
                if ($this->autofree) {
956
                if ($this->autofree) {
957
                    $this->free();
957
                    $this->free();
958
                }
958
                }
959
                return null;
959
                return null;
960
            }
960
            }
961
            if ($this->limit_type == 'emulate') {
961
            if ($this->limit_type == 'emulate') {
962
                $rownum = $this->row_counter;
962
                $rownum = $this->row_counter;
963
            }
963
            }
964
 
964
 
965
            $this->row_counter++;
965
            $this->row_counter++;
966
        }
966
        }
967
        $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
967
        $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
968
        if ($res === DB_OK) {
968
        if ($res === DB_OK) {
969
            if (isset($object_class)) {
969
            if (isset($object_class)) {
970
                // default mode specified in DB_common::fetchmode_object_class property
970
                // default mode specified in DB_common::fetchmode_object_class property
971
                if ($object_class == 'stdClass') {
971
                if ($object_class == 'stdClass') {
972
                    $arr = (object) $arr;
972
                    $arr = (object) $arr;
973
                } else {
973
                } else {
974
                    $arr = new $object_class($arr);
974
                    $arr = new $object_class($arr);
975
                }
975
                }
976
            }
976
            }
977
            return DB_OK;
977
            return DB_OK;
978
        }
978
        }
979
        if ($res == null && $this->autofree) {
979
        if ($res == null && $this->autofree) {
980
            $this->free();
980
            $this->free();
981
        }
981
        }
982
        return $res;
982
        return $res;
983
    }
983
    }
984
 
984
 
985
    // }}}
985
    // }}}
986
    // {{{ numCols()
986
    // {{{ numCols()
987
 
987
 
988
    /**
988
    /**
989
     * Get the the number of columns in a result set.
989
     * Get the the number of columns in a result set.
990
     *
990
     *
991
     * @return int the number of columns, or a DB error
991
     * @return int the number of columns, or a DB error
992
     *
992
     *
993
     * @access public
993
     * @access public
994
     */
994
     */
995
    function numCols()
995
    function numCols()
996
    {
996
    {
997
        return $this->dbh->numCols($this->result);
997
        return $this->dbh->numCols($this->result);
998
    }
998
    }
999
 
999
 
1000
    // }}}
1000
    // }}}
1001
    // {{{ numRows()
1001
    // {{{ numRows()
1002
 
1002
 
1003
    /**
1003
    /**
1004
     * Get the number of rows in a result set.
1004
     * Get the number of rows in a result set.
1005
     *
1005
     *
1006
     * @return int the number of rows, or a DB error
1006
     * @return int the number of rows, or a DB error
1007
     *
1007
     *
1008
     * @access public
1008
     * @access public
1009
     */
1009
     */
1010
    function numRows()
1010
    function numRows()
1011
    {
1011
    {
1012
        return $this->dbh->numRows($this->result);
1012
        return $this->dbh->numRows($this->result);
1013
    }
1013
    }
1014
 
1014
 
1015
    // }}}
1015
    // }}}
1016
    // {{{ nextResult()
1016
    // {{{ nextResult()
1017
 
1017
 
1018
    /**
1018
    /**
1019
     * Get the next result if a batch of queries was executed.
1019
     * Get the next result if a batch of queries was executed.
1020
     *
1020
     *
1021
     * @return bool true if a new result is available or false if not.
1021
     * @return bool true if a new result is available or false if not.
1022
     *
1022
     *
1023
     * @access public
1023
     * @access public
1024
     */
1024
     */
1025
    function nextResult()
1025
    function nextResult()
1026
    {
1026
    {
1027
        return $this->dbh->nextResult($this->result);
1027
        return $this->dbh->nextResult($this->result);
1028
    }
1028
    }
1029
 
1029
 
1030
    // }}}
1030
    // }}}
1031
    // {{{ free()
1031
    // {{{ free()
1032
 
1032
 
1033
    /**
1033
    /**
1034
     * Frees the resources allocated for this result set.
1034
     * Frees the resources allocated for this result set.
1035
     * @return  int error code
1035
     * @return  int error code
1036
     *
1036
     *
1037
     * @access public
1037
     * @access public
1038
     */
1038
     */
1039
    function free()
1039
    function free()
1040
    {
1040
    {
1041
        $err = $this->dbh->freeResult($this->result);
1041
        $err = $this->dbh->freeResult($this->result);
1042
        if (DB::isError($err)) {
1042
        if (DB::isError($err)) {
1043
            return $err;
1043
            return $err;
1044
        }
1044
        }
1045
        $this->result = false;
1045
        $this->result = false;
1046
        return true;
1046
        return true;
1047
    }
1047
    }
1048
 
1048
 
1049
    // }}}
1049
    // }}}
1050
    // {{{ tableInfo()
1050
    // {{{ tableInfo()
1051
 
1051
 
1052
    /**
1052
    /**
1053
     * @deprecated
1053
     * @deprecated
1054
     * @internal
1054
     * @internal
1055
     * @see DB_common::tableInfo()
1055
     * @see DB_common::tableInfo()
1056
     */
1056
     */
1057
    function tableInfo($mode = null)
1057
    function tableInfo($mode = null)
1058
    {
1058
    {
1059
        if (is_string($mode)) {
1059
        if (is_string($mode)) {
1060
            return $this->dbh->raiseError(DB_ERROR_NEED_MORE_DATA);
1060
            return $this->dbh->raiseError(DB_ERROR_NEED_MORE_DATA);
1061
        }
1061
        }
1062
        return $this->dbh->tableInfo($this, $mode);
1062
        return $this->dbh->tableInfo($this, $mode);
1063
    }
1063
    }
1064
 
1064
 
1065
    // }}}
1065
    // }}}
1066
    // {{{ getRowCounter()
1066
    // {{{ getRowCounter()
1067
 
1067
 
1068
    /**
1068
    /**
1069
     * returns the actual row number
1069
     * returns the actual row number
1070
     * @return integer
1070
     * @return integer
1071
     */
1071
     */
1072
    function getRowCounter()
1072
    function getRowCounter()
1073
    {
1073
    {
1074
        return $this->row_counter;
1074
        return $this->row_counter;
1075
    }
1075
    }
1076
    // }}}
1076
    // }}}
1077
}
1077
}
1078
 
1078
 
1079
// }}}
1079
// }}}
1080
// {{{ class DB_row
1080
// {{{ class DB_row
1081
 
1081
 
1082
/**
1082
/**
1083
 * Pear DB Row Object
1083
 * Pear DB Row Object
1084
 * @see DB_common::setFetchMode()
1084
 * @see DB_common::setFetchMode()
1085
 */
1085
 */
1086
class DB_row
1086
class DB_row
1087
{
1087
{
1088
    // {{{ constructor
1088
    // {{{ constructor
1089
 
1089
 
1090
    /**
1090
    /**
1091
     * constructor
1091
     * constructor
1092
     *
1092
     *
1093
     * @param resource row data as array
1093
     * @param resource row data as array
1094
     */
1094
     */
1095
    function DB_row(&$arr)
1095
    function DB_row(&$arr)
1096
    {
1096
    {
1097
        foreach ($arr as $key => $value) {
1097
        foreach ($arr as $key => $value) {
1098
            $this->$key = &$arr[$key];
1098
            $this->$key = &$arr[$key];
1099
        }
1099
        }
1100
    }
1100
    }
1101
 
1101
 
1102
    // }}}
1102
    // }}}
1103
}
1103
}
1104
 
1104
 
1105
// }}}
1105
// }}}
1106
 
1106
 
1107
/*
1107
/*
1108
 * Local variables:
1108
 * Local variables:
1109
 * tab-width: 4
1109
 * tab-width: 4
1110
 * c-basic-offset: 4
1110
 * c-basic-offset: 4
1111
 * End:
1111
 * End:
1112
 */
1112
 */
1113
 
1113
 
1114
?>
1114
?>