Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 4... Line 4...
4
 
4
 
5
/**
5
/**
6
 * The PEAR DB driver for PHP's mysqli extension
6
 * The PEAR DB driver for PHP's mysqli extension
7
 * for interacting with MySQL databases
7
 * for interacting with MySQL databases
8
 *
8
 *
9
 * PHP versions 4 and 5
9
 * PHP version 5
10
 *
10
 *
11
 * LICENSE: This source file is subject to version 3.0 of the PHP license
11
 * LICENSE: This source file is subject to version 3.0 of the PHP license
12
 * that is available through the world-wide-web at the following URI:
12
 * that is available through the world-wide-web at the following URI:
13
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
13
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
14
 * the PHP License and are unable to obtain it through the web, please
14
 * the PHP License and are unable to obtain it through the web, please
15
 * send a note to license@php.net so we can mail you a copy immediately.
15
 * send a note to license@php.net so we can mail you a copy immediately.
16
 *
16
 *
17
 * @category   Database
17
 * @category   Database
18
 * @package    DB
18
 * @package    DB
19
 * @author     Daniel Convissor <danielc@php.net>
19
 * @author     Daniel Convissor <danielc@php.net>
20
 * @copyright  1997-2005 The PHP Group
20
 * @copyright  1997-2007 The PHP Group
21
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
21
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
22
 * @version    CVS: $Id: mysqli.php,v 1.69 2005/03/04 23:12:36 danielc Exp $
22
 * @version    CVS: $Id$
23
 * @link       http://pear.php.net/package/DB
23
 * @link       http://pear.php.net/package/DB
Line 24... Line 24...
24
 */
24
 */
25
 
25
 
Line 39... Line 39...
39
 * These methods overload the ones declared in DB_common.
39
 * These methods overload the ones declared in DB_common.
40
 *
40
 *
41
 * @category   Database
41
 * @category   Database
42
 * @package    DB
42
 * @package    DB
43
 * @author     Daniel Convissor <danielc@php.net>
43
 * @author     Daniel Convissor <danielc@php.net>
44
 * @copyright  1997-2005 The PHP Group
44
 * @copyright  1997-2007 The PHP Group
45
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
45
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
46
 * @version    Release: 1.7.6
46
 * @version    Release: 1.9.2
47
 * @link       http://pear.php.net/package/DB
47
 * @link       http://pear.php.net/package/DB
48
 * @since      Class functional since Release 1.6.3
48
 * @since      Class functional since Release 1.6.3
49
 */
49
 */
50
class DB_mysqli extends DB_common
50
class DB_mysqli extends DB_common
51
{
51
{
Line 112... Line 112...
112
        1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
112
        1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
113
        1142 => DB_ERROR_ACCESS_VIOLATION,
113
        1142 => DB_ERROR_ACCESS_VIOLATION,
114
        1146 => DB_ERROR_NOSUCHTABLE,
114
        1146 => DB_ERROR_NOSUCHTABLE,
115
        1216 => DB_ERROR_CONSTRAINT,
115
        1216 => DB_ERROR_CONSTRAINT,
116
        1217 => DB_ERROR_CONSTRAINT,
116
        1217 => DB_ERROR_CONSTRAINT,
-
 
117
        1356 => DB_ERROR_DIVZERO,
-
 
118
        1451 => DB_ERROR_CONSTRAINT,
-
 
119
        1452 => DB_ERROR_CONSTRAINT,
117
    );
120
    );
Line 118... Line 121...
118
 
121
 
119
    /**
122
    /**
120
     * The raw database connection created by PHP
123
     * The raw database connection created by PHP
Line 208... Line 211...
208
        MYSQLI_TYPE_LONG_BLOB   => 'longblob',
211
        MYSQLI_TYPE_LONG_BLOB   => 'longblob',
209
        MYSQLI_TYPE_BLOB        => 'blob',
212
        MYSQLI_TYPE_BLOB        => 'blob',
210
        MYSQLI_TYPE_VAR_STRING  => 'varchar',
213
        MYSQLI_TYPE_VAR_STRING  => 'varchar',
211
        MYSQLI_TYPE_STRING      => 'char',
214
        MYSQLI_TYPE_STRING      => 'char',
212
        MYSQLI_TYPE_GEOMETRY    => 'geometry',
215
        MYSQLI_TYPE_GEOMETRY    => 'geometry',
-
 
216
        /* These constants are conditionally compiled in ext/mysqli, so we'll
-
 
217
         * define them by number rather than constant. */
-
 
218
        16                      => 'bit',
-
 
219
        246                     => 'decimal',
213
    );
220
    );
Line 214... Line 221...
214
 
221
 
215
 
222
 
Line 216... Line 223...
216
    // }}}
223
    // }}}
217
    // {{{ constructor
224
    // {{{ constructor
218
 
225
 
219
    /**
226
    /**
220
     * This constructor calls <kbd>$this->DB_common()</kbd>
227
     * This constructor calls <kbd>parent::__construct()</kbd>
221
     *
228
     *
222
     * @return void
229
     * @return void
223
     */
230
     */
224
    function DB_mysqli()
231
    function __construct()
Line 225... Line 232...
225
    {
232
    {
226
        $this->DB_common();
233
        parent::__construct();
Line 262... Line 269...
262
     * 
269
     * 
263
     * $options = array(
270
     * $options = array(
264
     *     'ssl' => true,
271
     *     'ssl' => true,
265
     * );
272
     * );
266
     * 
273
     * 
267
     * $db =& DB::connect($dsn, $options);
274
     * $db = DB::connect($dsn, $options);
268
     * if (PEAR::isError($db)) {
275
     * if (PEAR::isError($db)) {
269
     *     die($db->getMessage());
276
     *     die($db->getMessage());
270
     * }
277
     * }
271
     * </code>
278
     * </code>
272
     *
279
     *
Line 285... Line 292...
285
        if ($dsn['dbsyntax']) {
292
        if ($dsn['dbsyntax']) {
286
            $this->dbsyntax = $dsn['dbsyntax'];
293
            $this->dbsyntax = $dsn['dbsyntax'];
287
        }
294
        }
Line 288... Line 295...
288
 
295
 
289
        $ini = ini_get('track_errors');
296
        $ini = ini_get('track_errors');
290
        ini_set('track_errors', 1);
297
        @ini_set('track_errors', 1);
Line 291... Line 298...
291
        $php_errormsg = '';
298
        $php_errormsg = '';
292
 
299
 
293
        if ($this->getOption('ssl') === true) {
300
        if (((int) $this->getOption('ssl')) === 1) {
294
            $init = mysqli_init();
301
            $init = mysqli_init();
295
            mysqli_ssl_set(
302
            mysqli_ssl_set(
296
                $init,
303
                $init,
Line 320... Line 327...
320
                $dsn['port'],
327
                $dsn['port'],
321
                $dsn['socket']
328
                $dsn['socket']
322
            );
329
            );
323
        }
330
        }
Line 324... Line 331...
324
 
331
 
Line 325... Line 332...
325
        ini_set('track_errors', $ini);
332
        @ini_set('track_errors', $ini);
326
 
333
 
327
        if (!$this->connection) {
334
        if (!$this->connection) {
328
            if (($err = @mysqli_connect_error()) != '') {
335
            if (($err = @mysqli_connect_error()) != '') {
Line 370... Line 377...
370
     *                + the DB_OK constant for other successful queries
377
     *                + the DB_OK constant for other successful queries
371
     *                + a DB_Error object on failure
378
     *                + a DB_Error object on failure
372
     */
379
     */
373
    function simpleQuery($query)
380
    function simpleQuery($query)
374
    {
381
    {
375
        $ismanip = DB::isManip($query);
382
        $ismanip = $this->_checkManip($query);
376
        $this->last_query = $query;
383
        $this->last_query = $query;
377
        $query = $this->modifyQuery($query);
384
        $query = $this->modifyQuery($query);
378
        if ($this->_db) {
385
        if ($this->_db) {
379
            if (!@mysqli_select_db($this->connection, $this->_db)) {
386
            if (!@mysqli_select_db($this->connection, $this->_db)) {
380
                return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED);
387
                return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED);
Line 488... Line 495...
488
     *
495
     *
489
     * @see DB_result::free()
496
     * @see DB_result::free()
490
     */
497
     */
491
    function freeResult($result)
498
    function freeResult($result)
492
    {
499
    {
-
 
500
        if (! $result instanceof mysqli_result) {
-
 
501
            return false;
-
 
502
        }
493
        return @mysqli_free_result($result);
503
        mysqli_free_result($result);
-
 
504
        return true;
494
    }
505
    }
Line 495... Line 506...
495
 
506
 
496
    // }}}
507
    // }}}
Line 624... Line 635...
624
     *
635
     *
625
     * @return int  the number of rows.  A DB_Error object on failure.
636
     * @return int  the number of rows.  A DB_Error object on failure.
626
     */
637
     */
627
    function affectedRows()
638
    function affectedRows()
628
    {
639
    {
629
        if (DB::isManip($this->last_query)) {
640
        if ($this->_last_query_manip) {
630
            return @mysqli_affected_rows($this->connection);
641
            return @mysqli_affected_rows($this->connection);
631
        } else {
642
        } else {
632
            return 0;
643
            return 0;
633
        }
644
        }
634
     }
645
     }
Line 821... Line 832...
821
    // }}}
832
    // }}}
822
    // {{{ quoteIdentifier()
833
    // {{{ quoteIdentifier()
Line 823... Line 834...
823
 
834
 
824
    /**
835
    /**
-
 
836
     * Quotes a string so it can be safely used as a table or column name
825
     * Quotes a string so it can be safely used as a table or column name
837
     * (WARNING: using names that require this is a REALLY BAD IDEA)
826
     *
838
     *
827
     * MySQL can't handle the backtick character (<kbd>`</kbd>) in
839
     * WARNING:  Older versions of MySQL can't handle the backtick
828
     * table or column names.
840
     * character (<kbd>`</kbd>) in table or column names.
829
     *
841
     *
830
     * @param string $str  identifier name to be quoted
842
     * @param string $str  identifier name to be quoted
831
     *
843
     *
832
     * @return string  quoted identifier string
844
     * @return string  quoted identifier string
833
     *
845
     *
834
     * @see DB_common::quoteIdentifier()
846
     * @see DB_common::quoteIdentifier()
835
     * @since Method available since Release 1.6.0
847
     * @since Method available since Release 1.6.0
836
     */
848
     */
837
    function quoteIdentifier($str)
849
    function quoteIdentifier($str)
838
    {
850
    {
839
        return '`' . $str . '`';
851
        return '`' . str_replace('`', '``', $str) . '`';
Line 840... Line 852...
840
    }
852
    }
841
 
853
 
Line 876... Line 888...
876
     *
888
     *
877
     * @access protected
889
     * @access protected
878
     */
890
     */
879
    function modifyLimitQuery($query, $from, $count, $params = array())
891
    function modifyLimitQuery($query, $from, $count, $params = array())
880
    {
892
    {
881
        if (DB::isManip($query)) {
893
        if (DB::isManip($query) || $this->_next_query_manip) {
882
            return $query . " LIMIT $count";
894
            return $query . " LIMIT $count";
883
        } else {
895
        } else {
884
            return $query . " LIMIT $from, $count";
896
            return $query . " LIMIT $from, $count";
885
        }
897
        }
886
    }
898
    }
Line 952... Line 964...
952
     * @see DB_common::setOption()
964
     * @see DB_common::setOption()
953
     */
965
     */
954
    function tableInfo($result, $mode = null)
966
    function tableInfo($result, $mode = null)
955
    {
967
    {
956
        if (is_string($result)) {
968
        if (is_string($result)) {
-
 
969
            // Fix for bug #11580.
-
 
970
            if ($this->_db) {
-
 
971
                if (!@mysqli_select_db($this->connection, $this->_db)) {
-
 
972
                    return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED);
-
 
973
                }
-
 
974
            }
-
 
975
 
957
            /*
976
            /*
958
             * Probably received a table name.
977
             * Probably received a table name.
959
             * Create a result resource identifier.
978
             * Create a result resource identifier.
960
             */
979
             */
961
            $id = @mysqli_query($this->connection,
980
            $id = @mysqli_query($this->connection,
Line 976... Line 995...
976
             */
995
             */
977
            $id = $result;
996
            $id = $result;
978
            $got_string = false;
997
            $got_string = false;
979
        }
998
        }
Line 980... Line 999...
980
 
999
 
981
        if (!is_a($id, 'mysqli_result')) {
1000
        if (!is_object($id) || !is_a($id, 'mysqli_result')) {
982
            return $this->mysqliRaiseError(DB_ERROR_NEED_MORE_DATA);
1001
            return $this->mysqliRaiseError(DB_ERROR_NEED_MORE_DATA);
Line 983... Line 1002...
983
        }
1002
        }
984
 
1003
 
Line 1013... Line 1032...
1013
                'table' => $case_func($tmp->table),
1032
                'table' => $case_func($tmp->table),
1014
                'name'  => $case_func($tmp->name),
1033
                'name'  => $case_func($tmp->name),
1015
                'type'  => isset($this->mysqli_types[$tmp->type])
1034
                'type'  => isset($this->mysqli_types[$tmp->type])
1016
                                    ? $this->mysqli_types[$tmp->type]
1035
                                    ? $this->mysqli_types[$tmp->type]
1017
                                    : 'unknown',
1036
                                    : 'unknown',
-
 
1037
                // http://bugs.php.net/?id=36579
-
 
1038
                //  Doc Bug #36579: mysqli_fetch_field length handling
-
 
1039
                // https://bugs.php.net/bug.php?id=62426
-
 
1040
                //  Bug #62426: mysqli_fetch_field_direct returns incorrect
-
 
1041
                //  length on UTF8 fields
1018
                'len'   => $tmp->max_length,
1042
                'len'   => $tmp->length,
1019
                'flags' => $flags,
1043
                'flags' => $flags,
1020
            );
1044
            );
Line 1021... Line 1045...
1021
 
1045
 
1022
            if ($mode & DB_TABLEINFO_ORDER) {
1046
            if ($mode & DB_TABLEINFO_ORDER) {