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 mysql extension
6
 * The PEAR DB driver for PHP's mysql extension
7
 * for interacting with MySQL databases
7
 * for interacting with MySQL databases
8
 *
8
 *
9
 * PHP versions 4 and 5
9
 * PHP 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
Line 16... Line 16...
16
 *
16
 *
17
 * @category   Database
17
 * @category   Database
18
 * @package    DB
18
 * @package    DB
19
 * @author     Stig Bakken <ssb@php.net>
19
 * @author     Stig Bakken <ssb@php.net>
20
 * @author     Daniel Convissor <danielc@php.net>
20
 * @author     Daniel Convissor <danielc@php.net>
21
 * @copyright  1997-2005 The PHP Group
21
 * @copyright  1997-2007 The PHP Group
22
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
22
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
23
 * @version    CVS: $Id: mysql.php,v 1.117 2005/03/29 15:03:26 danielc Exp $
23
 * @version    CVS: $Id$
24
 * @link       http://pear.php.net/package/DB
24
 * @link       http://pear.php.net/package/DB
25
 */
25
 */
Line 26... Line 26...
26
 
26
 
27
/**
27
/**
Line 37... Line 37...
37
 *
37
 *
38
 * @category   Database
38
 * @category   Database
39
 * @package    DB
39
 * @package    DB
40
 * @author     Stig Bakken <ssb@php.net>
40
 * @author     Stig Bakken <ssb@php.net>
41
 * @author     Daniel Convissor <danielc@php.net>
41
 * @author     Daniel Convissor <danielc@php.net>
42
 * @copyright  1997-2005 The PHP Group
42
 * @copyright  1997-2007 The PHP Group
43
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
43
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
44
 * @version    Release: 1.7.6
44
 * @version    Release: 1.9.2
45
 * @link       http://pear.php.net/package/DB
45
 * @link       http://pear.php.net/package/DB
46
 */
46
 */
47
class DB_mysql extends DB_common
47
class DB_mysql extends DB_common
48
{
48
{
49
    // {{{ properties
49
    // {{{ properties
Line 109... Line 109...
109
        1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
109
        1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
110
        1142 => DB_ERROR_ACCESS_VIOLATION,
110
        1142 => DB_ERROR_ACCESS_VIOLATION,
111
        1146 => DB_ERROR_NOSUCHTABLE,
111
        1146 => DB_ERROR_NOSUCHTABLE,
112
        1216 => DB_ERROR_CONSTRAINT,
112
        1216 => DB_ERROR_CONSTRAINT,
113
        1217 => DB_ERROR_CONSTRAINT,
113
        1217 => DB_ERROR_CONSTRAINT,
-
 
114
        1356 => DB_ERROR_DIVZERO,
-
 
115
        1451 => DB_ERROR_CONSTRAINT,
-
 
116
        1452 => DB_ERROR_CONSTRAINT,
114
    );
117
    );
Line 115... Line 118...
115
 
118
 
116
    /**
119
    /**
117
     * The raw database connection created by PHP
120
     * The raw database connection created by PHP
Line 157... Line 160...
157
 
160
 
158
    // }}}
161
    // }}}
Line 159... Line 162...
159
    // {{{ constructor
162
    // {{{ constructor
160
 
163
 
161
    /**
164
    /**
162
     * This constructor calls <kbd>$this->DB_common()</kbd>
165
     * This constructor calls <kbd>parent::__construct()</kbd>
163
     *
166
     *
164
     * @return void
167
     * @return void
165
     */
168
     */
166
    function DB_mysql()
169
    function __construct()
167
    {
170
    {
Line 168... Line 171...
168
        $this->DB_common();
171
        parent::__construct();
169
    }
172
    }
Line 234... Line 237...
234
        $php_errormsg = '';
237
        $php_errormsg = '';
235
        if ($ini) {
238
        if ($ini) {
236
            $this->connection = @call_user_func_array($connect_function,
239
            $this->connection = @call_user_func_array($connect_function,
237
                                                      $params);
240
                                                      $params);
238
        } else {
241
        } else {
239
            ini_set('track_errors', 1);
242
            @ini_set('track_errors', 1);
240
            $this->connection = @call_user_func_array($connect_function,
243
            $this->connection = @call_user_func_array($connect_function,
241
                                                      $params);
244
                                                      $params);
242
            ini_set('track_errors', $ini);
245
            @ini_set('track_errors', $ini);
243
        }
246
        }
Line 244... Line 247...
244
 
247
 
245
        if (!$this->connection) {
248
        if (!$this->connection) {
246
            if (($err = @mysql_error()) != '') {
249
            if (($err = @mysql_error()) != '') {
Line 295... Line 298...
295
     *                + the DB_OK constant for other successful queries
298
     *                + the DB_OK constant for other successful queries
296
     *                + a DB_Error object on failure
299
     *                + a DB_Error object on failure
297
     */
300
     */
298
    function simpleQuery($query)
301
    function simpleQuery($query)
299
    {
302
    {
300
        $ismanip = DB::isManip($query);
303
        $ismanip = $this->_checkManip($query);
301
        $this->last_query = $query;
304
        $this->last_query = $query;
302
        $query = $this->modifyQuery($query);
305
        $query = $this->modifyQuery($query);
303
        if ($this->_db) {
306
        if ($this->_db) {
304
            if (!@mysql_select_db($this->_db, $this->connection)) {
307
            if (!@mysql_select_db($this->_db, $this->connection)) {
305
                return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
308
                return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
Line 417... Line 420...
417
     *
420
     *
418
     * @see DB_result::free()
421
     * @see DB_result::free()
419
     */
422
     */
420
    function freeResult($result)
423
    function freeResult($result)
421
    {
424
    {
422
        return @mysql_free_result($result);
425
        return is_resource($result) ? mysql_free_result($result) : false;
423
    }
426
    }
Line 424... Line 427...
424
 
427
 
425
    // }}}
428
    // }}}
Line 553... Line 556...
553
     *
556
     *
554
     * @return int  the number of rows.  A DB_Error object on failure.
557
     * @return int  the number of rows.  A DB_Error object on failure.
555
     */
558
     */
556
    function affectedRows()
559
    function affectedRows()
557
    {
560
    {
558
        if (DB::isManip($this->last_query)) {
561
        if ($this->_last_query_manip) {
559
            return @mysql_affected_rows($this->connection);
562
            return @mysql_affected_rows($this->connection);
560
        } else {
563
        } else {
561
            return 0;
564
            return 0;
562
        }
565
        }
563
     }
566
     }
Line 750... Line 753...
750
    // }}}
753
    // }}}
751
    // {{{ quoteIdentifier()
754
    // {{{ quoteIdentifier()
Line 752... Line 755...
752
 
755
 
753
    /**
756
    /**
-
 
757
     * Quotes a string so it can be safely used as a table or column name
754
     * Quotes a string so it can be safely used as a table or column name
758
     * (WARNING: using names that require this is a REALLY BAD IDEA)
755
     *
759
     *
756
     * MySQL can't handle the backtick character (<kbd>`</kbd>) in
760
     * WARNING:  Older versions of MySQL can't handle the backtick
757
     * table or column names.
761
     * character (<kbd>`</kbd>) in table or column names.
758
     *
762
     *
759
     * @param string $str  identifier name to be quoted
763
     * @param string $str  identifier name to be quoted
760
     *
764
     *
761
     * @return string  quoted identifier string
765
     * @return string  quoted identifier string
762
     *
766
     *
763
     * @see DB_common::quoteIdentifier()
767
     * @see DB_common::quoteIdentifier()
764
     * @since Method available since Release 1.6.0
768
     * @since Method available since Release 1.6.0
765
     */
769
     */
766
    function quoteIdentifier($str)
770
    function quoteIdentifier($str)
767
    {
771
    {
768
        return '`' . $str . '`';
-
 
769
    }
-
 
770
 
-
 
771
    // }}}
-
 
772
    // {{{ quote()
-
 
773
 
-
 
774
    /**
-
 
775
     * @deprecated  Deprecated in release 1.6.0
-
 
776
     */
-
 
777
    function quote($str)
-
 
778
    {
-
 
779
        return $this->quoteSmart($str);
772
        return '`' . str_replace('`', '``', $str) . '`';
Line 780... Line 773...
780
    }
773
    }
781
 
774
 
Line 850... Line 843...
850
     *
843
     *
851
     * @access protected
844
     * @access protected
852
     */
845
     */
853
    function modifyLimitQuery($query, $from, $count, $params = array())
846
    function modifyLimitQuery($query, $from, $count, $params = array())
854
    {
847
    {
855
        if (DB::isManip($query)) {
848
        if (DB::isManip($query) || $this->_next_query_manip) {
856
            return $query . " LIMIT $count";
849
            return $query . " LIMIT $count";
857
        } else {
850
        } else {
858
            return $query . " LIMIT $from, $count";
851
            return $query . " LIMIT $from, $count";
859
        }
852
        }
860
    }
853
    }
Line 926... Line 919...
926
     * @see DB_common::tableInfo()
919
     * @see DB_common::tableInfo()
927
     */
920
     */
928
    function tableInfo($result, $mode = null)
921
    function tableInfo($result, $mode = null)
929
    {
922
    {
930
        if (is_string($result)) {
923
        if (is_string($result)) {
-
 
924
            // Fix for bug #11580.
-
 
925
            if ($this->_db) {
-
 
926
                if (!@mysql_select_db($this->_db, $this->connection)) {
-
 
927
                    return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
-
 
928
                }
-
 
929
            }
-
 
930
            
931
            /*
931
            /*
932
             * Probably received a table name.
932
             * Probably received a table name.
933
             * Create a result resource identifier.
933
             * Create a result resource identifier.
934
             */
934
             */
935
            $id = @mysql_list_fields($this->dsn['database'],
935
            $id = @mysql_query("SELECT * FROM $result LIMIT 0",
936
                                     $result, $this->connection);
936
                               $this->connection);
937
            $got_string = true;
937
            $got_string = true;
938
        } elseif (isset($result->result)) {
938
        } elseif (isset($result->result)) {
939
            /*
939
            /*
940
             * Probably received a result object.
940
             * Probably received a result object.
941
             * Extract the result resource identifier.
941
             * Extract the result resource identifier.