inc/dal.inc.php
author rejo
Tue, 17 Apr 2007 21:18:14 +0000
changeset 5 ebf8868e99f5
parent 4 55ed92aa7cf5
permissions -rwxr-xr-x
[feladat @ 6] - Fixed bug in record.inc.php, search did never give matching domains. - Some modifications to Dutch translation.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     1
<?php
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
     2
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
     3
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     4
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
     5
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
     6
 * Database independent query interface
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
     7
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
     8
 * PHP versions 4 and 5
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
     9
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    10
 * LICENSE: This source file is subject to version 3.0 of the PHP license
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    11
 * that is available through the world-wide-web at the following URI:
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    12
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    13
 * the PHP License and are unable to obtain it through the web, please
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    14
 * send a note to license@php.net so we can mail you a copy immediately.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    15
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    16
 * @category   Database
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    17
 * @package    DB
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    18
 * @author     Stig Bakken <ssb@php.net>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    19
 * @author     Tomas V.V.Cox <cox@idecnet.com>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    20
 * @author     Daniel Convissor <danielc@php.net>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    21
 * @copyright  1997-2005 The PHP Group
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    22
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    23
 * @version    CVS: $Id: DB.php,v 1.80 2005/02/16 02:16:00 danielc Exp $
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    24
 * @link       http://pear.php.net/package/DB
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    25
 */
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    26
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    27
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    28
 * Obtain the PEAR class so it can be extended from
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    29
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    30
require_once 'PEAR.php';
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    31
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    32
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    33
// {{{ constants
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    34
// {{{ error codes
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    35
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    36
/**#@+
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    37
 * One of PEAR DB's portable error codes.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    38
 * @see DB_common::errorCode(), DB::errorMessage()
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    39
 *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    40
 * {@internal If you add an error code here, make sure you also add a textual
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    41
 * version of it in DB::errorMessage().}}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    42
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    43
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    44
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    45
 * The code returned by many methods upon success
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    46
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    47
define('DB_OK', 1);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    48
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    49
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    50
 * Unkown error
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    51
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    52
define('DB_ERROR', -1);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    53
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    54
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    55
 * Syntax error
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    56
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    57
define('DB_ERROR_SYNTAX', -2);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    58
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    59
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    60
 * Tried to insert a duplicate value into a primary or unique index
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    61
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    62
define('DB_ERROR_CONSTRAINT', -3);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    63
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    64
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    65
 * An identifier in the query refers to a non-existant object
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    66
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    67
define('DB_ERROR_NOT_FOUND', -4);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    68
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    69
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    70
 * Tried to create a duplicate object
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    71
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    72
define('DB_ERROR_ALREADY_EXISTS', -5);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    73
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    74
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    75
 * The current driver does not support the action you attempted
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    76
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    77
define('DB_ERROR_UNSUPPORTED', -6);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    78
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    79
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    80
 * The number of parameters does not match the number of placeholders
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    81
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    82
define('DB_ERROR_MISMATCH', -7);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    83
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    84
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    85
 * A literal submitted did not match the data type expected
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    86
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    87
define('DB_ERROR_INVALID', -8);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    88
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    89
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    90
 * The current DBMS does not support the action you attempted
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    91
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    92
define('DB_ERROR_NOT_CAPABLE', -9);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    93
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    94
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    95
 * A literal submitted was too long so the end of it was removed
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    96
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    97
define('DB_ERROR_TRUNCATED', -10);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    98
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
    99
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   100
 * A literal number submitted did not match the data type expected
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   101
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   102
define('DB_ERROR_INVALID_NUMBER', -11);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   103
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   104
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   105
 * A literal date submitted did not match the data type expected
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   106
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   107
define('DB_ERROR_INVALID_DATE', -12);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   108
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   109
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   110
 * Attempt to divide something by zero
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   111
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   112
define('DB_ERROR_DIVZERO', -13);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   113
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   114
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   115
 * A database needs to be selected
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   116
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   117
define('DB_ERROR_NODBSELECTED', -14);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   118
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   119
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   120
 * Could not create the object requested
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   121
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   122
define('DB_ERROR_CANNOT_CREATE', -15);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   123
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   124
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   125
 * Could not drop the database requested because it does not exist
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   126
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   127
define('DB_ERROR_CANNOT_DROP', -17);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   128
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   129
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   130
 * An identifier in the query refers to a non-existant table
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   131
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   132
define('DB_ERROR_NOSUCHTABLE', -18);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   133
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   134
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   135
 * An identifier in the query refers to a non-existant column
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   136
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   137
define('DB_ERROR_NOSUCHFIELD', -19);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   138
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   139
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   140
 * The data submitted to the method was inappropriate
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   141
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   142
define('DB_ERROR_NEED_MORE_DATA', -20);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   143
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   144
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   145
 * The attempt to lock the table failed
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   146
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   147
define('DB_ERROR_NOT_LOCKED', -21);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   148
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   149
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   150
 * The number of columns doesn't match the number of values
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   151
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   152
define('DB_ERROR_VALUE_COUNT_ON_ROW', -22);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   153
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   154
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   155
 * The DSN submitted has problems
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   156
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   157
define('DB_ERROR_INVALID_DSN', -23);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   158
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   159
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   160
 * Could not connect to the database
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   161
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   162
define('DB_ERROR_CONNECT_FAILED', -24);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   163
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   164
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   165
 * The PHP extension needed for this DBMS could not be found
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   166
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   167
define('DB_ERROR_EXTENSION_NOT_FOUND',-25);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   168
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   169
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   170
 * The present user has inadequate permissions to perform the task requestd
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   171
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   172
define('DB_ERROR_ACCESS_VIOLATION', -26);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   173
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   174
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   175
 * The database requested does not exist
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   176
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   177
define('DB_ERROR_NOSUCHDB', -27);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   178
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   179
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   180
 * Tried to insert a null value into a column that doesn't allow nulls
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   181
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   182
define('DB_ERROR_CONSTRAINT_NOT_NULL',-29);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   183
/**#@-*/
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   184
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   185
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   186
// }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   187
// {{{ prepared statement-related
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   188
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   189
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   190
/**#@+
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   191
 * Identifiers for the placeholders used in prepared statements.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   192
 * @see DB_common::prepare()
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   193
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   194
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   195
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   196
 * Indicates a scalar (<kbd>?</kbd>) placeholder was used
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   197
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   198
 * Quote and escape the value as necessary.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   199
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   200
define('DB_PARAM_SCALAR', 1);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   201
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   202
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   203
 * Indicates an opaque (<kbd>&</kbd>) placeholder was used
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   204
 *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   205
 * The value presented is a file name.  Extract the contents of that file
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   206
 * and place them in this column.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   207
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   208
define('DB_PARAM_OPAQUE', 2);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   209
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   210
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   211
 * Indicates a misc (<kbd>!</kbd>) placeholder was used
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   212
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   213
 * The value should not be quoted or escaped.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   214
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   215
define('DB_PARAM_MISC',   3);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   216
/**#@-*/
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   217
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   218
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   219
// }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   220
// {{{ binary data-related
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   221
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   222
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   223
/**#@+
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   224
 * The different ways of returning binary data from queries.
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   225
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   226
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   227
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   228
 * Sends the fetched data straight through to output
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   229
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   230
define('DB_BINMODE_PASSTHRU', 1);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   231
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   232
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   233
 * Lets you return data as usual
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   234
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   235
define('DB_BINMODE_RETURN', 2);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   236
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   237
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   238
 * Converts the data to hex format before returning it
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   239
 *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   240
 * For example the string "123" would become "313233".
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   241
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   242
define('DB_BINMODE_CONVERT', 3);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   243
/**#@-*/
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   244
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   245
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   246
// }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   247
// {{{ fetch modes
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   248
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   249
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   250
/**#@+
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   251
 * Fetch Modes.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   252
 * @see DB_common::setFetchMode()
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   253
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   254
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   255
/**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   256
 * Indicates the current default fetch mode should be used
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   257
 * @see DB_common::$fetchmode
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   258
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   259
define('DB_FETCHMODE_DEFAULT', 0);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   260
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   261
/**
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   262
 * Column data indexed by numbers, ordered from 0 and up
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   263
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   264
define('DB_FETCHMODE_ORDERED', 1);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   265
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   266
/**
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   267
 * Column data indexed by column names
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   268
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   269
define('DB_FETCHMODE_ASSOC', 2);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   270
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   271
/**
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   272
 * Column data as object properties
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   273
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   274
define('DB_FETCHMODE_OBJECT', 3);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   275
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   276
/**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   277
 * For multi-dimensional results, make the column name the first level
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   278
 * of the array and put the row number in the second level of the array
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   279
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   280
 * This is flipped from the normal behavior, which puts the row numbers
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   281
 * in the first level of the array and the column names in the second level.
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   282
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   283
define('DB_FETCHMODE_FLIPPED', 4);
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   284
/**#@-*/
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   285
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   286
/**#@+
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   287
 * Old fetch modes.  Left here for compatibility.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   288
 */
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   289
define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   290
define('DB_GETMODE_ASSOC',   DB_FETCHMODE_ASSOC);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   291
define('DB_GETMODE_FLIPPED', DB_FETCHMODE_FLIPPED);
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   292
/**#@-*/
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   293
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   294
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   295
// }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   296
// {{{ tableInfo() && autoPrepare()-related
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   297
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   298
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   299
/**#@+
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   300
 * The type of information to return from the tableInfo() method.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   301
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   302
 * Bitwised constants, so they can be combined using <kbd>|</kbd>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   303
 * and removed using <kbd>^</kbd>.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   304
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   305
 * @see DB_common::tableInfo()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   306
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   307
 * {@internal Since the TABLEINFO constants are bitwised, if more of them are
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   308
 * added in the future, make sure to adjust DB_TABLEINFO_FULL accordingly.}}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   309
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   310
define('DB_TABLEINFO_ORDER', 1);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   311
define('DB_TABLEINFO_ORDERTABLE', 2);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   312
define('DB_TABLEINFO_FULL', 3);
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   313
/**#@-*/
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   314
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   315
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   316
/**#@+
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   317
 * The type of query to create with the automatic query building methods.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   318
 * @see DB_common::autoPrepare(), DB_common::autoExecute()
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   319
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   320
define('DB_AUTOQUERY_INSERT', 1);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   321
define('DB_AUTOQUERY_UPDATE', 2);
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   322
/**#@-*/
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   323
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   324
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   325
// }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   326
// {{{ portability modes
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   327
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   328
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   329
/**#@+
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   330
 * Portability Modes.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   331
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   332
 * Bitwised constants, so they can be combined using <kbd>|</kbd>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   333
 * and removed using <kbd>^</kbd>.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   334
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   335
 * @see DB_common::setOption()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   336
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   337
 * {@internal Since the PORTABILITY constants are bitwised, if more of them are
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   338
 * added in the future, make sure to adjust DB_PORTABILITY_ALL accordingly.}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   339
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   340
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   341
/**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   342
 * Turn off all portability features
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   343
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   344
define('DB_PORTABILITY_NONE', 0);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   345
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   346
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   347
 * Convert names of tables and fields to lower case
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   348
 * when using the get*(), fetch*() and tableInfo() methods
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   349
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   350
define('DB_PORTABILITY_LOWERCASE', 1);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   351
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   352
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   353
 * Right trim the data output by get*() and fetch*()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   354
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   355
define('DB_PORTABILITY_RTRIM', 2);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   356
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   357
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   358
 * Force reporting the number of rows deleted
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   359
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   360
define('DB_PORTABILITY_DELETE_COUNT', 4);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   361
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   362
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   363
 * Enable hack that makes numRows() work in Oracle
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   364
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   365
define('DB_PORTABILITY_NUMROWS', 8);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   366
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   367
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   368
 * Makes certain error messages in certain drivers compatible
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   369
 * with those from other DBMS's
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   370
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   371
 * + mysql, mysqli:  change unique/primary key constraints
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   372
 *   DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   373
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   374
 * + odbc(access):  MS's ODBC driver reports 'no such field' as code
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   375
 *   07001, which means 'too few parameters.'  When this option is on
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   376
 *   that code gets mapped to DB_ERROR_NOSUCHFIELD.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   377
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   378
define('DB_PORTABILITY_ERRORS', 16);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   379
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   380
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   381
 * Convert null values to empty strings in data output by
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   382
 * get*() and fetch*()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   383
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   384
define('DB_PORTABILITY_NULL_TO_EMPTY', 32);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   385
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   386
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   387
 * Turn on all portability features
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   388
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   389
define('DB_PORTABILITY_ALL', 63);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   390
/**#@-*/
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   391
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   392
// }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   393
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   394
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   395
// }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   396
// {{{ class DB
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   397
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   398
/**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   399
 * Database independent query interface
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   400
 *
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   401
 * The main "DB" class is simply a container class with some static
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   402
 * methods for creating DB objects as well as some utility functions
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   403
 * common to all parts of DB.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   404
 *
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   405
 * The object model of DB is as follows (indentation means inheritance):
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   406
 * <pre>
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   407
 * DB           The main DB class.  This is simply a utility class
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   408
 *              with some "static" methods for creating DB objects as
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   409
 *              well as common utility functions for other DB classes.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   410
 *
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   411
 * DB_common    The base for each DB implementation.  Provides default
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   412
 * |            implementations (in OO lingo virtual methods) for
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   413
 * |            the actual DB implementations as well as a bunch of
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   414
 * |            query utility functions.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   415
 * |
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   416
 * +-DB_mysql   The DB implementation for MySQL.  Inherits DB_common.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   417
 *              When calling DB::factory or DB::connect for MySQL
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   418
 *              connections, the object returned is an instance of this
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   419
 *              class.
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   420
 * </pre>
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   421
 *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   422
 * @category   Database
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   423
 * @package    DB
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   424
 * @author     Stig Bakken <ssb@php.net>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   425
 * @author     Tomas V.V.Cox <cox@idecnet.com>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   426
 * @author     Daniel Convissor <danielc@php.net>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   427
 * @copyright  1997-2005 The PHP Group
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   428
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   429
 * @version    Release: @package_version@
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   430
 * @link       http://pear.php.net/package/DB
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   431
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   432
class DB
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   433
{
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   434
    // {{{ &factory()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   435
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   436
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   437
     * Create a new DB object for the specified database type but don't
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   438
     * connect to the database
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   439
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   440
     * @param string $type     the database type (eg "mysql")
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   441
     * @param array  $options  an associative array of option names and values
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   442
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   443
     * @return object  a new DB object.  A DB_Error object on failure.
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   444
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   445
     * @see DB_common::setOption()
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   446
     */
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   447
    function &factory($type, $options = false)
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   448
    {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   449
        if (!is_array($options)) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   450
            $options = array('persistent' => $options);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   451
        }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   452
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   453
        if (isset($options['debug']) && $options['debug'] >= 2) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   454
            // expose php errors with sufficient debug level
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   455
            include_once "DB/{$type}.php";
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   456
        } else {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   457
            @include_once "DB/{$type}.php";
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   458
        }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   459
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   460
        $classname = "DB_${type}";
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   461
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   462
        if (!class_exists($classname)) {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   463
            $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   464
                                    "Unable to include the DB/{$type}.php"
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   465
                                    . " file for '$dsn'",
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   466
                                    'DB_Error', true);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   467
            return $tmp;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   468
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   469
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   470
        @$obj =& new $classname;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   471
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   472
        foreach ($options as $option => $value) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   473
            $test = $obj->setOption($option, $value);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   474
            if (DB::isError($test)) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   475
                return $test;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   476
            }
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   477
        }
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   478
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   479
        return $obj;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   480
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   481
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   482
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   483
    // {{{ &connect()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   484
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   485
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   486
     * Create a new DB object including a connection to the specified database
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   487
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   488
     * Example 1.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   489
     * <code>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   490
     * require_once 'DB.php';
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   491
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   492
     * $dsn = 'pgsql://user:password@host/database';
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   493
     * $options = array(
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   494
     *     'debug'       => 2,
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   495
     *     'portability' => DB_PORTABILITY_ALL,
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   496
     * );
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   497
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   498
     * $db =& DB::connect($dsn, $options);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   499
     * if (PEAR::isError($db)) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   500
     *     die($db->getMessage());
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   501
     * }
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   502
     * </code>
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   503
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   504
     * @param mixed $dsn      the string "data source name" or array in the
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   505
     *                         format returned by DB::parseDSN()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   506
     * @param array $options  an associative array of option names and values
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   507
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   508
     * @return object  a new DB object.  A DB_Error object on failure.
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   509
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   510
     * @uses DB_dbase::connect(), DB_fbsql::connect(), DB_ibase::connect(),
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   511
     *       DB_ifx::connect(), DB_msql::connect(), DB_mssql::connect(),
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   512
     *       DB_mysql::connect(), DB_mysqli::connect(), DB_oci8::connect(),
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   513
     *       DB_odbc::connect(), DB_pgsql::connect(), DB_sqlite::connect(),
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   514
     *       DB_sybase::connect()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   515
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   516
     * @uses DB::parseDSN(), DB_common::setOption(), PEAR::isError()
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   517
     */
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   518
    function &connect($dsn, $options = array())
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   519
    {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   520
        $dsninfo = DB::parseDSN($dsn);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   521
        $type = $dsninfo['phptype'];
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   522
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   523
        if (!is_array($options)) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   524
            /*
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   525
             * For backwards compatibility.  $options used to be boolean,
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   526
             * indicating whether the connection should be persistent.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   527
             */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   528
            $options = array('persistent' => $options);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   529
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   530
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   531
        if (isset($options['debug']) && $options['debug'] >= 2) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   532
            // expose php errors with sufficient debug level
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   533
            include_once "DB/${type}.php";
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   534
        } else {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   535
            @include_once "DB/${type}.php";
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   536
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   537
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   538
        $classname = "DB_${type}";
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   539
        if (!class_exists($classname)) {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   540
            $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   541
                                    "Unable to include the DB/{$type}.php"
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   542
                                    . " file for '$dsn'",
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   543
                                    'DB_Error', true);
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   544
            return $tmp;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   545
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   546
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   547
        @$obj =& new $classname;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   548
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   549
        foreach ($options as $option => $value) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   550
            $test = $obj->setOption($option, $value);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   551
            if (DB::isError($test)) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   552
                return $test;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   553
            }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   554
        }
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   555
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   556
        $err = $obj->connect($dsninfo, $obj->getOption('persistent'));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   557
        if (DB::isError($err)) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   558
            $err->addUserInfo($dsn);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   559
            return $err;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   560
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   561
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   562
        return $obj;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   563
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   564
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   565
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   566
    // {{{ apiVersion()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   567
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   568
    /**
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   569
     * Return the DB API version
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   570
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   571
     * @return string  the DB API version number
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   572
     */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   573
    function apiVersion()
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   574
    {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   575
        return '@package_version@';
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   576
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   577
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   578
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   579
    // {{{ isError()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   580
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   581
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   582
     * Determines if a variable is a DB_Error object
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   583
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   584
     * @param mixed $value  the variable to check
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   585
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   586
     * @return bool  whether $value is DB_Error object
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   587
     */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   588
    function isError($value)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   589
    {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   590
        return is_a($value, 'DB_Error');
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   591
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   592
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   593
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   594
    // {{{ isConnection()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   595
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   596
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   597
     * Determines if a value is a DB_<driver> object
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   598
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   599
     * @param mixed $value  the value to test
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   600
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   601
     * @return bool  whether $value is a DB_<driver> object
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   602
     */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   603
    function isConnection($value)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   604
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   605
        return (is_object($value) &&
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   606
                is_subclass_of($value, 'db_common') &&
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   607
                method_exists($value, 'simpleQuery'));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   608
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   609
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   610
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   611
    // {{{ isManip()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   612
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   613
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   614
     * Tell whether a query is a data manipulation or data definition query
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   615
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   616
     * Examples of data manipulation queries are INSERT, UPDATE and DELETE.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   617
     * Examples of data definition queries are CREATE, DROP, ALTER, GRANT,
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   618
     * REVOKE.
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   619
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   620
     * @param string $query  the query
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   621
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   622
     * @return boolean  whether $query is a data manipulation query
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   623
     */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   624
    function isManip($query)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   625
    {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   626
        $manips = 'INSERT|UPDATE|DELETE|REPLACE|'
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   627
                . 'CREATE|DROP|'
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   628
                . 'LOAD DATA|SELECT .* INTO|COPY|'
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   629
                . 'ALTER|GRANT|REVOKE|'
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   630
                . 'LOCK|UNLOCK';
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   631
        if (preg_match('/^\s*"?(' . $manips . ')\s+/i', $query)) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   632
            return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   633
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   634
        return false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   635
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   636
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   637
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   638
    // {{{ errorMessage()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   639
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   640
    /**
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   641
     * Return a textual error message for a DB error code
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   642
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   643
     * @param integer $value  the DB error code
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   644
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   645
     * @return string  the error message or false if the error code was
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   646
     *                  not recognized
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   647
     */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   648
    function errorMessage($value)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   649
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   650
        static $errorMessages;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   651
        if (!isset($errorMessages)) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   652
            $errorMessages = array(
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   653
                DB_ERROR                    => 'unknown error',
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   654
                DB_ERROR_ACCESS_VIOLATION   => 'insufficient permissions',
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   655
                DB_ERROR_ALREADY_EXISTS     => 'already exists',
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   656
                DB_ERROR_CANNOT_CREATE      => 'can not create',
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   657
                DB_ERROR_CANNOT_DROP        => 'can not drop',
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   658
                DB_ERROR_CONNECT_FAILED     => 'connect failed',
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   659
                DB_ERROR_CONSTRAINT         => 'constraint violation',
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   660
                DB_ERROR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint',
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   661
                DB_ERROR_DIVZERO            => 'division by zero',
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   662
                DB_ERROR_EXTENSION_NOT_FOUND=> 'extension not found',
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   663
                DB_ERROR_INVALID            => 'invalid',
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   664
                DB_ERROR_INVALID_DATE       => 'invalid date or time',
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   665
                DB_ERROR_INVALID_DSN        => 'invalid DSN',
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   666
                DB_ERROR_INVALID_NUMBER     => 'invalid number',
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   667
                DB_ERROR_MISMATCH           => 'mismatch',
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   668
                DB_ERROR_NEED_MORE_DATA     => 'insufficient data supplied',
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   669
                DB_ERROR_NODBSELECTED       => 'no database selected',
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   670
                DB_ERROR_NOSUCHDB           => 'no such database',
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   671
                DB_ERROR_NOSUCHFIELD        => 'no such field',
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   672
                DB_ERROR_NOSUCHTABLE        => 'no such table',
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   673
                DB_ERROR_NOT_CAPABLE        => 'DB backend not capable',
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   674
                DB_ERROR_NOT_FOUND          => 'not found',
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   675
                DB_ERROR_NOT_LOCKED         => 'not locked',
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   676
                DB_ERROR_SYNTAX             => 'syntax error',
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   677
                DB_ERROR_UNSUPPORTED        => 'not supported',
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   678
                DB_ERROR_TRUNCATED          => 'truncated',
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   679
                DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   680
                DB_OK                       => 'no error',
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   681
            );
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   682
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   683
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   684
        if (DB::isError($value)) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   685
            $value = $value->getCode();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   686
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   687
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   688
        return isset($errorMessages[$value]) ? $errorMessages[$value]
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   689
                     : $errorMessages[DB_ERROR];
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   690
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   691
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   692
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   693
    // {{{ parseDSN()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   694
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   695
    /**
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   696
     * Parse a data source name
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   697
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   698
     * Additional keys can be added by appending a URI query string to the
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   699
     * end of the DSN.
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   700
     *
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   701
     * The format of the supplied DSN is in its fullest form:
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   702
     * <code>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   703
     *  phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   704
     * </code>
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   705
     *
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   706
     * Most variations are allowed:
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   707
     * <code>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   708
     *  phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   709
     *  phptype://username:password@hostspec/database_name
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   710
     *  phptype://username:password@hostspec
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   711
     *  phptype://username@hostspec
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   712
     *  phptype://hostspec/database
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   713
     *  phptype://hostspec
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   714
     *  phptype(dbsyntax)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   715
     *  phptype
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   716
     * </code>
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   717
     *
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   718
     * @param string $dsn Data Source Name to be parsed
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   719
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   720
     * @return array an associative array with the following keys:
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   721
     *  + phptype:  Database backend used in PHP (mysql, odbc etc.)
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   722
     *  + dbsyntax: Database used with regards to SQL syntax etc.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   723
     *  + protocol: Communication protocol to use (tcp, unix etc.)
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   724
     *  + hostspec: Host specification (hostname[:port])
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   725
     *  + database: Database to use on the DBMS server
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   726
     *  + username: User name for login
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   727
     *  + password: Password for login
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   728
     */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   729
    function parseDSN($dsn)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   730
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   731
        $parsed = array(
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   732
            'phptype'  => false,
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   733
            'dbsyntax' => false,
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   734
            'username' => false,
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   735
            'password' => false,
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   736
            'protocol' => false,
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   737
            'hostspec' => false,
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   738
            'port'     => false,
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   739
            'socket'   => false,
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   740
            'database' => false,
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   741
        );
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   742
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   743
        if (is_array($dsn)) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   744
            $dsn = array_merge($parsed, $dsn);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   745
            if (!$dsn['dbsyntax']) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   746
                $dsn['dbsyntax'] = $dsn['phptype'];
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   747
            }
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   748
            return $dsn;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   749
        }
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   750
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   751
        // Find phptype and dbsyntax
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   752
        if (($pos = strpos($dsn, '://')) !== false) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   753
            $str = substr($dsn, 0, $pos);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   754
            $dsn = substr($dsn, $pos + 3);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   755
        } else {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   756
            $str = $dsn;
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   757
            $dsn = null;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   758
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   759
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   760
        // Get phptype and dbsyntax
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   761
        // $str => phptype(dbsyntax)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   762
        if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   763
            $parsed['phptype']  = $arr[1];
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   764
            $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   765
        } else {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   766
            $parsed['phptype']  = $str;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   767
            $parsed['dbsyntax'] = $str;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   768
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   769
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   770
        if (!count($dsn)) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   771
            return $parsed;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   772
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   773
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   774
        // Get (if found): username and password
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   775
        // $dsn => username:password@protocol+hostspec/database
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   776
        if (($at = strrpos($dsn,'@')) !== false) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   777
            $str = substr($dsn, 0, $at);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   778
            $dsn = substr($dsn, $at + 1);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   779
            if (($pos = strpos($str, ':')) !== false) {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   780
                $parsed['username'] = rawurldecode(substr($str, 0, $pos));
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   781
                $parsed['password'] = rawurldecode(substr($str, $pos + 1));
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   782
            } else {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   783
                $parsed['username'] = rawurldecode($str);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   784
            }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   785
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   786
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   787
        // Find protocol and hostspec
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   788
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   789
        if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   790
            // $dsn => proto(proto_opts)/database
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   791
            $proto       = $match[1];
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   792
            $proto_opts  = $match[2] ? $match[2] : false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   793
            $dsn         = $match[3];
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   794
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   795
        } else {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   796
            // $dsn => protocol+hostspec/database (old format)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   797
            if (strpos($dsn, '+') !== false) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   798
                list($proto, $dsn) = explode('+', $dsn, 2);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   799
            }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   800
            if (strpos($dsn, '/') !== false) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   801
                list($proto_opts, $dsn) = explode('/', $dsn, 2);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   802
            } else {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   803
                $proto_opts = $dsn;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   804
                $dsn = null;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   805
            }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   806
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   807
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   808
        // process the different protocol options
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   809
        $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   810
        $proto_opts = rawurldecode($proto_opts);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   811
        if ($parsed['protocol'] == 'tcp') {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   812
            if (strpos($proto_opts, ':') !== false) {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   813
                list($parsed['hostspec'],
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   814
                     $parsed['port']) = explode(':', $proto_opts);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   815
            } else {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   816
                $parsed['hostspec'] = $proto_opts;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   817
            }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   818
        } elseif ($parsed['protocol'] == 'unix') {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   819
            $parsed['socket'] = $proto_opts;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   820
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   821
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   822
        // Get dabase if any
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   823
        // $dsn => database
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   824
        if ($dsn) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   825
            if (($pos = strpos($dsn, '?')) === false) {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   826
                // /database
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   827
                $parsed['database'] = rawurldecode($dsn);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   828
            } else {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   829
                // /database?param1=value1&param2=value2
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   830
                $parsed['database'] = rawurldecode(substr($dsn, 0, $pos));
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   831
                $dsn = substr($dsn, $pos + 1);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   832
                if (strpos($dsn, '&') !== false) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   833
                    $opts = explode('&', $dsn);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   834
                } else { // database?param1=value1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   835
                    $opts = array($dsn);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   836
                }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   837
                foreach ($opts as $opt) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   838
                    list($key, $value) = explode('=', $opt);
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   839
                    if (!isset($parsed[$key])) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   840
                        // don't allow params overwrite
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   841
                        $parsed[$key] = rawurldecode($value);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   842
                    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   843
                }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   844
            }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   845
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   846
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   847
        return $parsed;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   848
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   849
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   850
    // }}}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   851
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   852
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   853
// }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   854
// {{{ class DB_Error
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   855
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   856
/**
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   857
 * DB_Error implements a class for reporting portable database error
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   858
 * messages
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   859
 *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   860
 * @category   Database
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   861
 * @package    DB
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   862
 * @author     Stig Bakken <ssb@php.net>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   863
 * @copyright  1997-2005 The PHP Group
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   864
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   865
 * @version    Release: @package_version@
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   866
 * @link       http://pear.php.net/package/DB
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   867
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   868
class DB_Error extends PEAR_Error
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   869
{
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   870
    // {{{ constructor
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   871
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   872
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   873
     * DB_Error constructor
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   874
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   875
     * @param mixed $code       DB error code, or string with error message
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   876
     * @param int   $mode       what "error mode" to operate in
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   877
     * @param int   $level      what error level to use for $mode &
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   878
     *                           PEAR_ERROR_TRIGGER
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   879
     * @param mixed $debuginfo  additional debug info, such as the last query
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   880
     *
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   881
     * @see PEAR_Error
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   882
     */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   883
    function DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   884
                      $level = E_USER_NOTICE, $debuginfo = null)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   885
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   886
        if (is_int($code)) {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   887
            $this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code,
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   888
                              $mode, $level, $debuginfo);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   889
        } else {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   890
            $this->PEAR_Error("DB Error: $code", DB_ERROR,
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   891
                              $mode, $level, $debuginfo);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   892
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   893
    }
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   894
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   895
    // }}}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   896
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   897
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   898
// }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   899
// {{{ class DB_result
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   900
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   901
/**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   902
 * This class implements a wrapper for a DB result set
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   903
 *
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   904
 * A new instance of this class will be returned by the DB implementation
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   905
 * after processing a query that returns data.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   906
 *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   907
 * @category   Database
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   908
 * @package    DB
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   909
 * @author     Stig Bakken <ssb@php.net>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   910
 * @copyright  1997-2005 The PHP Group
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   911
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   912
 * @version    Release: @package_version@
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   913
 * @link       http://pear.php.net/package/DB
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   914
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   915
class DB_result
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   916
{
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   917
    // {{{ properties
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   918
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   919
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   920
     * Should results be freed automatically when there are no more rows?
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   921
     * @var boolean
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   922
     * @see DB_common::$options
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   923
     */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   924
    var $autofree;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   925
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   926
    /**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   927
     * A reference to the DB_<driver> object
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   928
     * @var object
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   929
     */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   930
    var $dbh;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   931
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   932
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   933
     * The current default fetch mode
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   934
     * @var integer
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   935
     * @see DB_common::$fetchmode
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   936
     */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   937
    var $fetchmode;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   938
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   939
    /**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   940
     * The name of the class into which results should be fetched when
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   941
     * DB_FETCHMODE_OBJECT is in effect
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   942
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   943
     * @var string
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   944
     * @see DB_common::$fetchmode_object_class
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   945
     */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   946
    var $fetchmode_object_class;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   947
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   948
    /**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   949
     * The number of rows to fetch from a limit query
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   950
     * @var integer
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   951
     */
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   952
    var $limit_count = null;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   953
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   954
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   955
     * The row to start fetching from in limit queries
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   956
     * @var integer
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   957
     */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   958
    var $limit_from = null;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   959
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   960
    /**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   961
     * The execute parameters that created this result
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   962
     * @var array
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   963
     * @since Property available since Release 1.7.0
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   964
     */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   965
    var $parameters;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   966
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   967
    /**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   968
     * The query string that created this result
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   969
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   970
     * Copied here incase it changes in $dbh, which is referenced
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   971
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   972
     * @var string
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   973
     * @since Property available since Release 1.7.0
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   974
     */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   975
    var $query;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   976
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   977
    /**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   978
     * The query result resource id created by PHP
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   979
     * @var resource
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   980
     */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   981
    var $result;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   982
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   983
    /**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   984
     * The present row being dealt with
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   985
     * @var integer
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   986
     */
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   987
    var $row_counter = null;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   988
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   989
    /**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   990
     * The prepared statement resource id created by PHP in $dbh
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   991
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   992
     * This resource is only available when the result set was created using
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   993
     * a driver's native execute() method, not PEAR DB's emulated one.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   994
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   995
     * Copied here incase it changes in $dbh, which is referenced
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   996
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   997
     * {@internal  Mainly here because the InterBase/Firebird API is only
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   998
     * able to retrieve data from result sets if the statemnt handle is
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
   999
     * still in scope.}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1000
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1001
     * @var resource
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1002
     * @since Property available since Release 1.7.0
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1003
     */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1004
    var $statement;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1005
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1006
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1007
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1008
    // {{{ constructor
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1009
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1010
    /**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1011
     * This constructor sets the object's properties
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1012
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1013
     * @param object   &$dbh     the DB object reference
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1014
     * @param resource $result   the result resource id
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1015
     * @param array    $options  an associative array with result options
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1016
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1017
     * @return void
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1018
     */
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1019
    function DB_result(&$dbh, $result, $options = array())
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1020
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1021
        $this->autofree    = $dbh->options['autofree'];
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1022
        $this->dbh         = &$dbh;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1023
        $this->fetchmode   = $dbh->fetchmode;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1024
        $this->fetchmode_object_class = $dbh->fetchmode_object_class;
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1025
        $this->parameters  = $dbh->last_parameters;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1026
        $this->query       = $dbh->last_query;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1027
        $this->result      = $result;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1028
        $this->statement   = empty($dbh->last_stmt) ? null : $dbh->last_stmt;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1029
        foreach ($options as $key => $value) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1030
            $this->setOption($key, $value);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1031
        }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1032
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1033
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1034
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1035
     * Set options for the DB_result object
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1036
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1037
     * @param string $key    the option to set
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1038
     * @param mixed  $value  the value to set the option to
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1039
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1040
     * @return void
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1041
     */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1042
    function setOption($key, $value = null)
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1043
    {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1044
        switch ($key) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1045
            case 'limit_from':
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1046
                $this->limit_from = $value;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1047
                break;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1048
            case 'limit_count':
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1049
                $this->limit_count = $value;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1050
        }
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1051
    }
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1052
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1053
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1054
    // {{{ fetchRow()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1055
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1056
    /**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1057
     * Fetch a row of data and return it by reference into an array
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1058
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1059
     * The type of array returned can be controlled either by setting this
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1060
     * method's <var>$fetchmode</var> parameter or by changing the default
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1061
     * fetch mode setFetchMode() before calling this method.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1062
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1063
     * There are two options for standardizing the information returned
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1064
     * from databases, ensuring their values are consistent when changing
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1065
     * DBMS's.  These portability options can be turned on when creating a
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1066
     * new DB object or by using setOption().
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1067
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1068
     *   + <var>DB_PORTABILITY_LOWERCASE</var>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1069
     *     convert names of fields to lower case
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1070
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1071
     *   + <var>DB_PORTABILITY_RTRIM</var>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1072
     *     right trim the data
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1073
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1074
     * @param int $fetchmode  the constant indicating how to format the data
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1075
     * @param int $rownum     the row number to fetch (index starts at 0)
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1076
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1077
     * @return mixed  an array or object containing the row's data,
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1078
     *                 NULL when the end of the result set is reached
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1079
     *                 or a DB_Error object on failure.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1080
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1081
     * @see DB_common::setOption(), DB_common::setFetchMode()
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1082
     */
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1083
    function &fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1084
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1085
        if ($fetchmode === DB_FETCHMODE_DEFAULT) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1086
            $fetchmode = $this->fetchmode;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1087
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1088
        if ($fetchmode === DB_FETCHMODE_OBJECT) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1089
            $fetchmode = DB_FETCHMODE_ASSOC;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1090
            $object_class = $this->fetchmode_object_class;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1091
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1092
        if ($this->limit_from !== null) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1093
            if ($this->row_counter === null) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1094
                $this->row_counter = $this->limit_from;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1095
                // Skip rows
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1096
                if ($this->dbh->features['limit'] === false) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1097
                    $i = 0;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1098
                    while ($i++ < $this->limit_from) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1099
                        $this->dbh->fetchInto($this->result, $arr, $fetchmode);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1100
                    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1101
                }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1102
            }
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1103
            if ($this->row_counter >= ($this->limit_from + $this->limit_count))
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1104
            {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1105
                if ($this->autofree) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1106
                    $this->free();
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1107
                }
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1108
                $tmp = null;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1109
                return $tmp;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1110
            }
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1111
            if ($this->dbh->features['limit'] === 'emulate') {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1112
                $rownum = $this->row_counter;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1113
            }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1114
            $this->row_counter++;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1115
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1116
        $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1117
        if ($res === DB_OK) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1118
            if (isset($object_class)) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1119
                // The default mode is specified in the
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1120
                // DB_common::fetchmode_object_class property
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1121
                if ($object_class == 'stdClass') {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1122
                    $arr = (object) $arr;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1123
                } else {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1124
                    $arr = &new $object_class($arr);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1125
                }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1126
            }
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1127
            return $arr;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1128
        }
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1129
        if ($res == null && $this->autofree) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1130
            $this->free();
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1131
        }
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1132
        return $res;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1133
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1134
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1135
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1136
    // {{{ fetchInto()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1137
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1138
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1139
     * Fetch a row of data into an array which is passed by reference
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1140
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1141
     * The type of array returned can be controlled either by setting this
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1142
     * method's <var>$fetchmode</var> parameter or by changing the default
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1143
     * fetch mode setFetchMode() before calling this method.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1144
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1145
     * There are two options for standardizing the information returned
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1146
     * from databases, ensuring their values are consistent when changing
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1147
     * DBMS's.  These portability options can be turned on when creating a
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1148
     * new DB object or by using setOption().
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1149
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1150
     *   + <var>DB_PORTABILITY_LOWERCASE</var>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1151
     *     convert names of fields to lower case
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1152
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1153
     *   + <var>DB_PORTABILITY_RTRIM</var>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1154
     *     right trim the data
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1155
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1156
     * @param array &$arr       the variable where the data should be placed
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1157
     * @param int   $fetchmode  the constant indicating how to format the data
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1158
     * @param int   $rownum     the row number to fetch (index starts at 0)
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1159
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1160
     * @return mixed  DB_OK if a row is processed, NULL when the end of the
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1161
     *                 result set is reached or a DB_Error object on failure
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1162
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1163
     * @see DB_common::setOption(), DB_common::setFetchMode()
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1164
     */
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1165
    function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1166
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1167
        if ($fetchmode === DB_FETCHMODE_DEFAULT) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1168
            $fetchmode = $this->fetchmode;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1169
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1170
        if ($fetchmode === DB_FETCHMODE_OBJECT) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1171
            $fetchmode = DB_FETCHMODE_ASSOC;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1172
            $object_class = $this->fetchmode_object_class;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1173
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1174
        if ($this->limit_from !== null) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1175
            if ($this->row_counter === null) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1176
                $this->row_counter = $this->limit_from;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1177
                // Skip rows
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1178
                if ($this->dbh->features['limit'] === false) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1179
                    $i = 0;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1180
                    while ($i++ < $this->limit_from) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1181
                        $this->dbh->fetchInto($this->result, $arr, $fetchmode);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1182
                    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1183
                }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1184
            }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1185
            if ($this->row_counter >= (
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1186
                    $this->limit_from + $this->limit_count))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1187
            {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1188
                if ($this->autofree) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1189
                    $this->free();
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1190
                }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1191
                return null;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1192
            }
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1193
            if ($this->dbh->features['limit'] === 'emulate') {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1194
                $rownum = $this->row_counter;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1195
            }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1196
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1197
            $this->row_counter++;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1198
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1199
        $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1200
        if ($res === DB_OK) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1201
            if (isset($object_class)) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1202
                // default mode specified in the
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1203
                // DB_common::fetchmode_object_class property
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1204
                if ($object_class == 'stdClass') {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1205
                    $arr = (object) $arr;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1206
                } else {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1207
                    $arr = new $object_class($arr);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1208
                }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1209
            }
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1210
            return DB_OK;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1211
        }
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1212
        if ($res == null && $this->autofree) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1213
            $this->free();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1214
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1215
        return $res;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1216
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1217
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1218
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1219
    // {{{ numCols()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1220
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1221
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1222
     * Get the the number of columns in a result set
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1223
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1224
     * @return int  the number of columns.  A DB_Error object on failure.
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1225
     */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1226
    function numCols()
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1227
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1228
        return $this->dbh->numCols($this->result);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1229
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1230
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1231
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1232
    // {{{ numRows()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1233
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1234
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1235
     * Get the number of rows in a result set
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1236
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1237
     * @return int  the number of rows.  A DB_Error object on failure.
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1238
     */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1239
    function numRows()
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1240
    {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1241
        if ($this->dbh->features['numrows'] === 'emulate'
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1242
            && $this->dbh->options['portability'] & DB_PORTABILITY_NUMROWS)
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1243
        {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1244
            if ($this->dbh->features['prepare']) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1245
                $res = $this->dbh->query($this->query, $this->parameters);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1246
            } else {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1247
                $res = $this->dbh->query($this->query);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1248
            }
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1249
            if (DB::isError($res)) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1250
                return $res;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1251
            }
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1252
            $i = 0;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1253
            while ($res->fetchInto($tmp, DB_FETCHMODE_ORDERED)) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1254
                $i++;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1255
            }
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1256
            return $i;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1257
        } else {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1258
            return $this->dbh->numRows($this->result);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1259
        }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1260
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1261
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1262
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1263
    // {{{ nextResult()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1264
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1265
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1266
     * Get the next result if a batch of queries was executed
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1267
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1268
     * @return bool  true if a new result is available or false if not
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1269
     */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1270
    function nextResult()
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1271
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1272
        return $this->dbh->nextResult($this->result);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1273
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1274
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1275
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1276
    // {{{ free()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1277
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1278
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1279
     * Frees the resources allocated for this result set
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1280
     *
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1281
     * @return bool  true on success.  A DB_Error object on failure.
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1282
     */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1283
    function free()
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1284
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1285
        $err = $this->dbh->freeResult($this->result);
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1286
        if (DB::isError($err)) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1287
            return $err;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1288
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1289
        $this->result = false;
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1290
        $this->statement = false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1291
        return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1292
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1293
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1294
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1295
    // {{{ tableInfo()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1296
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1297
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1298
     * @see DB_common::tableInfo()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1299
     * @deprecated Method deprecated some time before Release 1.2
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1300
     */
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1301
    function tableInfo($mode = null)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1302
    {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1303
        if (is_string($mode)) {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1304
            return $this->dbh->raiseError(DB_ERROR_NEED_MORE_DATA);
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1305
        }
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1306
        return $this->dbh->tableInfo($this, $mode);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1307
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1308
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1309
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1310
    // {{{ getQuery()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1311
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1312
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1313
     * Determine the query string that created this result
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1314
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1315
     * @return string  the query string
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1316
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1317
     * @since Method available since Release 1.7.0
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1318
     */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1319
    function getQuery()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1320
    {
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1321
        return $this->query;
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1322
    }
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1323
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1324
    // }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1325
    // {{{ getRowCounter()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1326
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1327
    /**
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1328
     * Tells which row number is currently being processed
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1329
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1330
     * @return integer  the current row being looked at.  Starts at 1.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1331
     */
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1332
    function getRowCounter()
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1333
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1334
        return $this->row_counter;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1335
    }
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1336
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1337
    // }}}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1338
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1339
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1340
// }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1341
// {{{ class DB_row
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1342
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1343
/**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1344
 * PEAR DB Row Object
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1345
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1346
 * The object contains a row of data from a result set.  Each column's data
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1347
 * is placed in a property named for the column.
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1348
 *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1349
 * @category   Database
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1350
 * @package    DB
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1351
 * @author     Stig Bakken <ssb@php.net>
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1352
 * @copyright  1997-2005 The PHP Group
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1353
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1354
 * @version    Release: @package_version@
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1355
 * @link       http://pear.php.net/package/DB
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1356
 * @see        DB_common::setFetchMode()
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1357
 */
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1358
class DB_row
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1359
{
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1360
    // {{{ constructor
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1361
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1362
    /**
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1363
     * The constructor places a row's data into properties of this object
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1364
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1365
     * @param array  the array containing the row's data
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1366
     *
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1367
     * @return void
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1368
     */
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1369
    function DB_row(&$arr)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1370
    {
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1371
        foreach ($arr as $key => $value) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1372
            $this->$key = &$arr[$key];
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1373
        }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1374
    }
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1375
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1376
    // }}}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1377
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1378
4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1379
// }}}
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1380
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1381
/*
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1382
 * Local variables:
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1383
 * tab-width: 4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1384
 * c-basic-offset: 4
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1385
 * End:
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1386
 */
55ed92aa7cf5 [feladat @ 5]
rejo
parents: 1
diff changeset
  1387
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1388
?>