⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdb2.php

📁 This is the script which used on 10minutemail.com for temporary email.
💻 PHP
📖 第 1 页 / 共 5 页
字号:
     * </code>
     *
     * @param   string  Data Source Name to be parsed
     *
     * @return  array   an associative array with the following keys:
     *  + phptype:  Database backend used in PHP (mysql, odbc etc.)
     *  + dbsyntax: Database used with regards to SQL syntax etc.
     *  + protocol: Communication protocol to use (tcp, unix etc.)
     *  + hostspec: Host specification (hostname[:port])
     *  + database: Database to use on the DBMS server
     *  + username: User name for login
     *  + password: Password for login
     *
     * @access  public
     * @author  Tomas V.V.Cox <cox@idecnet.com>
     */
    function parseDSN($dsn)
    {
        $parsed = $GLOBALS['_MDB2_dsninfo_default'];

        if (is_array($dsn)) {
            $dsn = array_merge($parsed, $dsn);
            if (!$dsn['dbsyntax']) {
                $dsn['dbsyntax'] = $dsn['phptype'];
            }
            return $dsn;
        }

        // Find phptype and dbsyntax
        if (($pos = strpos($dsn, '://')) !== false) {
            $str = substr($dsn, 0, $pos);
            $dsn = substr($dsn, $pos + 3);
        } else {
            $str = $dsn;
            $dsn = null;
        }

        // Get phptype and dbsyntax
        // $str => phptype(dbsyntax)
        if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
            $parsed['phptype']  = $arr[1];
            $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
        } else {
            $parsed['phptype']  = $str;
            $parsed['dbsyntax'] = $str;
        }

        if (!count($dsn)) {
            return $parsed;
        }

        // Get (if found): username and password
        // $dsn => username:password@protocol+hostspec/database
        if (($at = strrpos($dsn,'@')) !== false) {
            $str = substr($dsn, 0, $at);
            $dsn = substr($dsn, $at + 1);
            if (($pos = strpos($str, ':')) !== false) {
                $parsed['username'] = rawurldecode(substr($str, 0, $pos));
                $parsed['password'] = rawurldecode(substr($str, $pos + 1));
            } else {
                $parsed['username'] = rawurldecode($str);
            }
        }

        // Find protocol and hostspec

        // $dsn => proto(proto_opts)/database
        if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
            $proto       = $match[1];
            $proto_opts  = $match[2] ? $match[2] : false;
            $dsn         = $match[3];

        // $dsn => protocol+hostspec/database (old format)
        } else {
            if (strpos($dsn, '+') !== false) {
                list($proto, $dsn) = explode('+', $dsn, 2);
            }
            if (strpos($dsn, '/') !== false) {
                list($proto_opts, $dsn) = explode('/', $dsn, 2);
            } else {
                $proto_opts = $dsn;
                $dsn = null;
            }
        }

        // process the different protocol options
        $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
        $proto_opts = rawurldecode($proto_opts);
        if (strpos($proto_opts, ':') !== false) {
            list($proto_opts, $parsed['port']) = explode(':', $proto_opts);
        }
        if ($parsed['protocol'] == 'tcp') {
            $parsed['hostspec'] = $proto_opts;
        } elseif ($parsed['protocol'] == 'unix') {
            $parsed['socket'] = $proto_opts;
        }

        // Get dabase if any
        // $dsn => database
        if ($dsn) {
            // /database
            if (($pos = strpos($dsn, '?')) === false) {
                $parsed['database'] = $dsn;
            // /database?param1=value1&param2=value2
            } else {
                $parsed['database'] = substr($dsn, 0, $pos);
                $dsn = substr($dsn, $pos + 1);
                if (strpos($dsn, '&') !== false) {
                    $opts = explode('&', $dsn);
                } else { // database?param1=value1
                    $opts = array($dsn);
                }
                foreach ($opts as $opt) {
                    list($key, $value) = explode('=', $opt);
                    if (!isset($parsed[$key])) {
                        // don't allow params overwrite
                        $parsed[$key] = rawurldecode($value);
                    }
                }
            }
        }

        return $parsed;
    }

    // }}}
    // {{{ function fileExists($file)

    /**
     * Checks if a file exists in the include path
     *
     * @param   string  filename
     *
     * @return  bool    true success and false on error
     *
     * @access  public
     */
    function fileExists($file)
    {
        // safe_mode does notwork with is_readable()
        if (!@ini_get('safe_mode')) {
             $dirs = explode(PATH_SEPARATOR, ini_get('include_path'));
             foreach ($dirs as $dir) {
                 if (is_readable($dir . DIRECTORY_SEPARATOR . $file)) {
                     return true;
                 }
            }
        } else {
            $fp = @fopen($file, 'r', true);
            if (is_resource($fp)) {
                @fclose($fp);
                return true;
            }
        }
        return false;
    }
    // }}}
}

// }}}
// {{{ class MDB2_Error extends PEAR_Error

/**
 * MDB2_Error implements a class for reporting portable database error
 * messages.
 *
 * @package     MDB2
 * @category    Database
 * @author Stig Bakken <ssb@fast.no>
 */
class MDB2_Error extends PEAR_Error
{
    // {{{ constructor: function MDB2_Error($code = MDB2_ERROR, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE, $debuginfo = null)

    /**
     * MDB2_Error constructor.
     *
     * @param   mixed   MDB2 error code, or string with error message.
     * @param   int     what 'error mode' to operate in
     * @param   int     what error level to use for $mode & PEAR_ERROR_TRIGGER
     * @param   smixed   additional debug info, such as the last query
     */
    function MDB2_Error($code = MDB2_ERROR, $mode = PEAR_ERROR_RETURN,
              $level = E_USER_NOTICE, $debuginfo = null)
    {
        $this->PEAR_Error('MDB2 Error: '.MDB2::errorMessage($code), $code,
            $mode, $level, $debuginfo);
    }

    // }}}
}

// }}}
// {{{ class MDB2_Driver_Common extends PEAR

/**
 * MDB2_Driver_Common: Base class that is extended by each MDB2 driver
 *
 * @package     MDB2
 * @category    Database
 * @author      Lukas Smith <smith@pooteeweet.org>
 */
class MDB2_Driver_Common extends PEAR
{
    // {{{ Variables (Properties)

    /**
     * index of the MDB2 object within the $GLOBALS['_MDB2_databases'] array
     * @var     int
     * @access  public
     */
    var $db_index = 0;

    /**
     * DSN used for the next query
     * @var     array
     * @access  protected
     */
    var $dsn = array();

    /**
     * DSN that was used to create the current connection
     * @var     array
     * @access  protected
     */
    var $connected_dsn = array();

    /**
     * connection resource
     * @var     mixed
     * @access  protected
     */
    var $connection = 0;

    /**
     * if the current opened connection is a persistent connection
     * @var     bool
     * @access  protected
     */
    var $opened_persistent;

    /**
     * the name of the database for the next query
     * @var     string
     * @access  protected
     */
    var $database_name = '';

    /**
     * the name of the database currently selected
     * @var     string
     * @access  protected
     */
    var $connected_database_name = '';

    /**
     * server version information
     * @var     string
     * @access  protected
     */
    var $connected_server_info = '';

    /**
     * list of all supported features of the given driver
     * @var     array
     * @access  public
     */
    var $supported = array(
        'sequences' => false,
        'indexes' => false,
        'affected_rows' => false,
        'summary_functions' => false,
        'order_by_text' => false,
        'transactions' => false,
        'savepoints' => false,
        'current_id' => false,
        'limit_queries' => false,
        'LOBs' => false,
        'replace' => false,
        'sub_selects' => false,
        'auto_increment' => false,
        'primary_key' => false,
        'result_introspection' => false,
        'prepared_statements' => false,
        'identifier_quoting' => false,
        'pattern_escaping' => false,
        'new_link' => false,
    );

    /**
     * Array of supported options that can be passed to the MDB2 instance.
     * 
     * The options can be set during object creation, using
     * MDB2::connect(), MDB2::factory() or MDB2::singleton(). The options can 
     * also be set after the object is created, using MDB2::setOptions() or 
     * MDB2_Driver_Common::setOption().
     * The list of available option includes:
     * <ul>
     *  <li>$options['ssl'] -> boolean: determines if ssl should be used for connections</li>
     *  <li>$options['field_case'] -> CASE_LOWER|CASE_UPPER: determines what case to force on field/table names</li>
     *  <li>$options['disable_query'] -> boolean: determines if queries should be executed</li>
     *  <li>$options['result_class'] -> string: class used for result sets</li>
     *  <li>$options['buffered_result_class'] -> string: class used for buffered result sets</li>
     *  <li>$options['result_wrap_class'] -> string: class used to wrap result sets into</li>
     *  <li>$options['result_buffering'] -> boolean should results be buffered or not?</li>
     *  <li>$options['fetch_class'] -> string: class to use when fetch mode object is used</li>
     *  <li>$options['persistent'] -> boolean: persistent connection?</li>
     *  <li>$options['debug'] -> integer: numeric debug level</li>
     *  <li>$options['debug_handler'] -> string: function/method that captures debug messages</li>
     *  <li>$options['debug_expanded_output'] -> bool: BC option to determine if more context information should be send to the debug handler</li>
     *  <li>$options['default_text_field_length'] -> integer: default text field length to use</li>
     *  <li>$options['lob_buffer_length'] -> integer: LOB buffer length</li>
     *  <li>$options['log_line_break'] -> string: line-break format</li>
     *  <li>$options['idxname_format'] -> string: pattern for index name</li>
     *  <li>$options['seqname_format'] -> string: pattern for sequence name</li>
     *  <li>$options['savepoint_format'] -> string: pattern for auto generated savepoint names</li>
     *  <li>$options['statement_format'] -> string: pattern for prepared statement names</li>
     *  <li>$options['seqcol_name'] -> string: sequence column name</li>
     *  <li>$options['quote_identifier'] -> boolean: if identifier quoting should be done when check_option is used</li>
     *  <li>$options['use_transactions'] -> boolean: if transaction use should be enabled</li>
     *  <li>$options['decimal_places'] -> integer: number of decimal places to handle</li>
     *  <li>$options['portability'] -> integer: portability constant</li>
     *  <li>$options['modules'] -> array: short to long module name mapping for __call()</li>
     *  <li>$options['emulate_prepared'] -> boolean: force prepared statements to be emulated</li>
     *  <li>$options['datatype_map'] -> array: map user defined datatypes to other primitive datatypes</li>
     *  <li>$options['datatype_map_callback'] -> array: callback function/method that should be called</li>
     * </ul>
     *
     * @var     array
     * @access  public
     * @see     MDB2::connect()
     * @see     MDB2::factory()
     * @see     MDB2::singleton()
     * @see     MDB2_Driver_Common::setOption()
     */
    var $options = array(
        'ssl' => false,
        'field_case' => CASE_LOWER,
        'disable_query' => false,
        'result_class' => 'MDB2_Result_%s',
        'buffered_result_class' => 'MDB2_BufferedResult_%s',
        'result_wrap_class' => false,
        'result_buffering' => true,
        'fetch_class' => 'stdClass',
        'persistent' => false,
        'debug' => 0,
        'debug_handler' => 'MDB2_defaultDebugOutput',
        'debug_expanded_output' => false,
        'default_text_field_length' => 4096,
        'lob_buffer_length' => 8192,
        'log_line_break' => "\n",
        'idxname_format' => '%s_idx',
        'seqname_format' => '%s_seq',
        'savepoint_format' => 'MDB2_SAVEPOINT_%s',
        'statement_format' => 'MDB2_STATEMENT_%1$s_%2$s',
        'seqcol_name' => 'sequence',
        'quote_identifier' => false,
        'use_transactions' => true,
        'decimal_places' => 2,
        'portability' => MDB2_PORTABILITY_ALL,
        'modules' => array(
            'ex' => 'Extended',
            'dt' => 'Datatype',
            'mg' => 'Manager',
            'rv' => 'Reverse',
            'na' => 'Native',
            'fc' => 'Function',
        ),
        'emulate_prepared' => false,
        'datatype_map' => array(),
        'datatype_map_callback' => array(),
    );

    /**
     * string array
     * @var     string
     * @access  protected
     */
    var $string_quoting = array('start' => "'", 'end' => "'", 'escape' => false, 'escape_pattern' => false);

    /**
     * identifier quoting
     * @var     array
     * @access  protected
     */
    var $identifier_quoting = array('start' => '"', 'end' => '"', 'escape' => '"');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -