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

📄 adodb.php

📁 PhpWiki是sourceforge的一个开源项目
💻 PHP
📖 第 1 页 / 共 5 页
字号:
        if (substr($backend_type,0,5) == 'mysql') {            $dbh->Execute("REPLACE INTO $recent_tbl"                          . " (id, latestversion, latestmajor, latestminor)"                          . " SELECT id, $maxversion, $maxmajor, $maxminor"                          . " FROM $version_tbl"                          . ( $pageid ? " WHERE id=$pageid" : "")                          . " GROUP BY id" );        } else {            $this->lock(array('recent'));            $dbh->Execute("DELETE FROM $recent_tbl"                      . ( $pageid ? " WHERE id=$pageid" : ""));            $dbh->Execute( "INSERT INTO $recent_tbl"                           . " (id, latestversion, latestmajor, latestminor)"                           . " SELECT id, $maxversion, $maxmajor, $maxminor"                           . " FROM $version_tbl"                           . ( $pageid ? " WHERE id=$pageid" : "")                           . " GROUP BY id" );            $this->unlock(array('recent'));        }    }    function _update_nonempty_table($pageid = false) {        $dbh = &$this->_dbh;        extract($this->_table_names);        extract($this->_expressions);        $pageid = (int)$pageid;        extract($this->_expressions);        $this->lock(array('nonempty'));        $dbh->Execute("DELETE FROM $nonempty_tbl"                      . ( $pageid ? " WHERE id=$pageid" : ""));        $dbh->Execute("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) {            $this->_dbh->StartTrans();        if ($this->_lock_count++ == 0) {            $this->_current_lock = $tables;            $this->_lock_tables($tables, $write_lock);        }    }    /**     * Overridden by non-transaction safe backends.     */    function _lock_tables($tables, $write_lock) {        return $this->_current_lock;    }        /**     * 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->_dbh->CompleteTrans(! $force);            $this->_current_lock = false;            return;        }        if (--$this->_lock_count <= 0 || $force) {            $this->_unlock_tables($tables);            $this->_current_lock = false;            $this->_lock_count = 0;        }            $this->_dbh->CompleteTrans(! $force);    }    /**     * overridden by non-transaction safe backends     */    function _unlock_tables($tables, $write_lock) {        return;    }    /**     * 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() {        return $this->_dbh->_connectionID;    }    function getRow($query) {        return $this->_dbh->getRow($query);    }    function listOfTables() {        return $this->_dbh->MetaTables();    }        // other database needs another connection and other privileges.    function listOfFields($database, $table) {        $field_list = array();        $old_db = $this->database();        if ($database != $old_db) {            $conn = $this->_dbh->Connect($this->_parsedDSN['hostspec'],             				 DBADMIN_USER ? DBADMIN_USER : $this->_parsedDSN['username'],                                          DBADMIN_PASSWD ? DBADMIN_PASSWD : $this->_parsedDSN['password'],                                          $database);        }        foreach ($this->_dbh->MetaColumns($table, false) as $field) {            $field_list[] = $field->name;        }        if ($database != $old_db) {            $this->_dbh->close();            $conn = $this->_dbh->Connect($this->_parsedDSN['hostspec'],             				 $this->_parsedDSN['username'],                                          $this->_parsedDSN['password'],                                          $old_db);        }        return $field_list;    }};class WikiDB_backend_ADODB_generic_iterextends WikiDB_backend_iterator{    function WikiDB_backend_ADODB_generic_iter($backend, $query_result, $field_list = NULL) {        $this->_backend = &$backend;        $this->_result = $query_result;        if (is_null($field_list)) {            // No field list passed, retrieve from DB            // WikiLens is using the iterator behind the scene            $field_list = array();            $fields = $query_result->FieldCount();            for ($i = 0; $i < $fields ; $i++) {                $field_info = $query_result->FetchField($i);                array_push($field_list, $field_info->name);            }        }        $this->_fields = $field_list;    }        function count() {        if (!$this->_result) {            return false;        }        $count = $this->_result->numRows();        //$this->_result->Close();        return $count;    }    function next() {        $result = &$this->_result;        $backend = &$this->_backend;        if (!$result || $result->EOF) {            $this->free();            return false;        }        // Convert array to hash        $i = 0;        $rec_num = $result->fields;        foreach ($this->_fields as $field) {            $rec_assoc[$field] = $rec_num[$i++];        }        // check if the cache can be populated here?        $result->MoveNext();        return $rec_assoc;    }    function free () {        if ($this->_result) {            /* call mysql_free_result($this->_queryID) */            $this->_result->Close();            $this->_result = false;        }    }}class WikiDB_backend_ADODB_iterextends WikiDB_backend_ADODB_generic_iter{    function next() {        $result = &$this->_result;        $backend = &$this->_backend;        if (!$result || $result->EOF) {            $this->free();            return false;        }        // Convert array to hash        $i = 0;        $rec_num = $result->fields;        foreach ($this->_fields as $field) {            $rec_assoc[$field] = $rec_num[$i++];        }        $result->MoveNext();        if (isset($rec_assoc['pagedata']))            $rec_assoc['pagedata'] = $backend->_extract_page_data($rec_assoc['pagedata'], $rec_assoc['hits']);        if (!empty($rec_assoc['version'])) {            $rec_assoc['versiondata'] = $backend->_extract_version_data_assoc($rec_assoc);        }        return $rec_assoc;    }}class WikiDB_backend_ADODB_searchextends WikiDB_backend_search{    function WikiDB_backend_ADODB_search(&$search, &$dbh) {        $this->_dbh =& $dbh;        $this->_case_exact = $search->_case_exact;    }    function _pagename_match_clause($node) {        $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.     *  + 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     *     * @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;        }

⌨️ 快捷键说明

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