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

📄 pdo.php

📁 PhpWiki是sourceforge的一个开源项目
💻 PHP
📖 第 1 页 / 共 4 页
字号:
        $dbh = &$this->_dbh;        extract($this->_table_names);        extract($this->_expressions);        $pageid = (int)$pageid;        extract($this->_expressions);        $this->lock(array('nonempty'));        $dbh->query("DELETE FROM $nonempty_tbl"                    . ( $pageid ? " WHERE id=$pageid" : ""));        $dbh->query("INSERT INTO $nonempty_tbl (id)"                    . " SELECT $recent_tbl.id"                    . " FROM $recent_tbl, $version_tbl"                    . " WHERE $recent_tbl.id=$version_tbl.id"                    . "       AND version=latestversion"                    // We have some specifics here (Oracle)                    //. "  AND content<>''"                    . "  AND content $notempty"                    . ( $pageid ? " AND $recent_tbl.id=$pageid" : ""));        $this->unlock(array('nonempty'));    }    /**     * Grab a write lock on the tables in the SQL database.     *     * Calls can be nested.  The tables won't be unlocked until     * _unlock_database() is called as many times as _lock_database().     *     * @access protected     */    function lock($tables, $write_lock = true) {        if ($this->_lock_count++ == 0) {            $this->_current_lock = $tables;            if (!$this->_hasTransactions)                $this->_lock_tables($tables, $write_lock);        }    }    /**     * Overridden by non-transaction safe backends.     */    function _lock_tables($tables, $write_lock) {        $lock_type = $write_lock ? "WRITE" : "READ";        foreach ($this->_table_names as $key => $table) {            $locks[] = "$table $lock_type";        }        $this->_dbh->query("LOCK TABLES " . join(",", $locks));    }        /**     * Release a write lock on the tables in the SQL database.     *     * @access protected     *     * @param $force boolean Unlock even if not every call to lock() has been matched     * by a call to unlock().     *     * @see _lock_database     */    function unlock($tables = false, $force = false) {        if ($this->_lock_count == 0) {            $this->_current_lock = false;            return;        }        if (--$this->_lock_count <= 0 || $force) {            if (!$this->_hasTransactions)                $this->_unlock_tables($tables);            $this->_current_lock = false;            $this->_lock_count = 0;        }    }    /**     * overridden by non-transaction safe backends     */    function _unlock_tables($tables) {        $this->_dbh->query("UNLOCK TABLES");    }    /**     * Serialize data     */    function _serialize($data) {        if (empty($data))            return '';        assert(is_array($data));        return serialize($data);    }    /**     * Unserialize data     */    function _unserialize($data) {        return empty($data) ? array() : unserialize($data);    }    /* some variables and functions for DB backend abstraction (action=upgrade) */    function database () {        return $this->_dbh->database;    }    function backendType() {        return $this->_dbh->databaseType;    }    function connection() {        trigger_error("PDO: connectionID unsupported", E_USER_ERROR);        return false;    }    function listOfTables() {        trigger_error("PDO: virtual listOfTables", E_USER_ERROR);        return array();    }    function listOfFields($database, $table) {        trigger_error("PDO: virtual listOfFields", E_USER_ERROR);        return array();    }};class WikiDB_backend_PDO_generic_iterextends WikiDB_backend_iterator{    function WikiDB_backend_PDO_generic_iter($backend, $query_result, $field_list = NULL) {        $this->_backend = &$backend;        $this->_result = $query_result;        //$this->_fields = $field_list;    }        function count() {        if (!is_object($this->_result)) {            return false;        }        $count = $this->_result->rowCount();        return $count;    }    function next() {        $result = &$this->_result;        if (!is_object($result)) {            return false;        }        return $result->fetch(PDO_FETCH_BOTH);    }    function free () {        if ($this->_result) {            unset($this->_result);        }    }}class WikiDB_backend_PDO_iterextends WikiDB_backend_PDO_generic_iter{    function next() {        $result = &$this->_result;        if (!is_object($result)) {            return false;        }        $this->_backend = &$backend;        $rec = $result->fetch(PDO_FETCH_ASSOC);        if (isset($rec['pagedata']))            $rec['pagedata'] = $backend->_extract_page_data($rec['pagedata'], $rec['hits']);        if (!empty($rec['version'])) {            $rec['versiondata'] = $backend->_extract_version_data_assoc($rec);        }        return $rec;    }}class WikiDB_backend_PDO_searchextends WikiDB_backend_search{    function WikiDB_backend_PDO_search(&$search, &$dbh) {        $this->_dbh =& $dbh;        $this->_case_exact = $search->_case_exact;    }    function _pagename_match_clause($node) {        // word already quoted by TextSearchQuery_node_word::_sql_quote()        $word = $node->sql();        return ($this->_case_exact                 ? "pagename LIKE '$word'"                : "LOWER(pagename) LIKE '$word'");    }    function _fulltext_match_clause($node) {         $word = $node->sql();        return ($this->_case_exact                ? "pagename LIKE '$word' OR content LIKE '$word'"                : "LOWER(pagename) LIKE '$word' OR content LIKE '$word'");    }}// Following function taken from Pear::DB (prev. from adodb-pear.inc.php).// Eventually, change index.php to provide the relevant information// directly?    /**     * Parse a data source name.     *     * Additional keys can be added by appending a URI query string to the     * end of the DSN.     *     * The format of the supplied DSN is in its fullest form:     * <code>     *  phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true     * </code>     *     * Most variations are allowed:     * <code>     *  phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644     *  phptype://username:password@hostspec/database_name     *  phptype://username:password@hostspec     *  phptype://username@hostspec     *  phptype://hostspec/database     *  phptype://hostspec     *  phptype(dbsyntax)     *  phptype     * </code>     *     * @param string $dsn 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. (ignored with PDO)     *  + protocol: Communication protocol to use (tcp, unix, pipe etc.)     *  + hostspec: Host specification (hostname[:port])     *  + database: Database to use on the DBMS server     *  + username: User name for login     *  + password: Password for login     *     * @author Tomas V.V.Cox <cox@idecnet.com>     */    function parseDSN($dsn)    {        $parsed = array(            'phptype'  => false,            'dbsyntax' => false,            'username' => false,            'password' => false,            'protocol' => false,            'hostspec' => false,            'port'     => false,            'socket'   => false,            'database' => false,        );        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 ($parsed['protocol'] == 'tcp') {            if (strpos($proto_opts, ':') !== false) {                list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);            } else {                $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;    }// $Log: PDO.php,v $// Revision 1.2  2005/02/11 14:45:45  rurban// support ENABLE_LIVESEARCH, enable PDO sessions//// Revision 1.1  2005/02/10 19:01:22  rurban// add PDO support//// (c-file-style: "gnu")// Local Variables:// mode: php// tab-width: 8// c-basic-offset: 4// c-hanging-comment-ender-p: nil// indent-tabs-mode: nil// End:   ?>

⌨️ 快捷键说明

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