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

📄 pgsql.php

📁 开源邮件管理系统
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php// +----------------------------------------------------------------------+// | PHP versions 4 and 5                                                 |// +----------------------------------------------------------------------+// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,                 |// | Stig. S. Bakken, Lukas Smith                                         |// | All rights reserved.                                                 |// +----------------------------------------------------------------------+// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB  |// | API as well as database abstraction for PHP applications.            |// | This LICENSE is in the BSD license style.                            |// |                                                                      |// | Redistribution and use in source and binary forms, with or without   |// | modification, are permitted provided that the following conditions   |// | are met:                                                             |// |                                                                      |// | Redistributions of source code must retain the above copyright       |// | notice, this list of conditions and the following disclaimer.        |// |                                                                      |// | Redistributions in binary form must reproduce the above copyright    |// | notice, this list of conditions and the following disclaimer in the  |// | documentation and/or other materials provided with the distribution. |// |                                                                      |// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |// | Lukas Smith nor the names of his contributors may be used to endorse |// | or promote products derived from this software without specific prior|// | written permission.                                                  |// |                                                                      |// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|// |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |// | POSSIBILITY OF SUCH DAMAGE.                                          |// +----------------------------------------------------------------------+// | Author: Paul Cooper <pgc@ucecom.com>                                 |// +----------------------------------------------------------------------+//// $Id: pgsql.php,v 1.82 2008/03/05 12:55:57 afz Exp $require_once 'MDB2/Driver/Manager/Common.php';/** * MDB2 MySQL driver for the management modules * * @package MDB2 * @category Database * @author  Paul Cooper <pgc@ucecom.com> */class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common{    // {{{ createDatabase()    /**     * create a new database     *     * @param string $name    name of the database that should be created     * @param array  $options array with charset info     *     * @return mixed MDB2_OK on success, a MDB2 error on failure     * @access public     */    function createDatabase($name, $options = array())    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $name  = $db->quoteIdentifier($name, true);        $query = 'CREATE DATABASE ' . $name;        if (!empty($options['charset'])) {            $query .= ' WITH ENCODING ' . $db->quote($options['charset'], 'text');        }        return $db->standaloneQuery($query, null, true);    }    // }}}    // {{{ alterDatabase()    /**     * alter an existing database     *     * @param string $name    name of the database that is intended to be changed     * @param array  $options array with name, owner info     *     * @return mixed MDB2_OK on success, a MDB2 error on failure     * @access public     */    function alterDatabase($name, $options = array())    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $query = 'ALTER DATABASE '. $db->quoteIdentifier($name, true);        if (!empty($options['name'])) {            $query .= ' RENAME TO ' . $options['name'];        }        if (!empty($options['owner'])) {            $query .= ' OWNER TO ' . $options['owner'];        }        return $db->standaloneQuery($query, null, true);    }    // }}}    // {{{ dropDatabase()    /**     * drop an existing database     *     * @param string $name name of the database that should be dropped     * @return mixed MDB2_OK on success, a MDB2 error on failure     * @access public     */    function dropDatabase($name)    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $name = $db->quoteIdentifier($name, true);        $query = "DROP DATABASE $name";        return $db->standaloneQuery($query, null, true);    }    // }}}    // {{{ _getAdvancedFKOptions()    /**     * Return the FOREIGN KEY query section dealing with non-standard options     * as MATCH, INITIALLY DEFERRED, ON UPDATE, ...     *     * @param array $definition     * @return string     * @access protected     */    function _getAdvancedFKOptions($definition)    {        $query = '';        if (!empty($definition['match'])) {            $query .= ' MATCH '.$definition['match'];        }        if (!empty($definition['onupdate'])) {            $query .= ' ON UPDATE '.$definition['onupdate'];        }        if (!empty($definition['ondelete'])) {            $query .= ' ON DELETE '.$definition['ondelete'];        }        if (!empty($definition['deferrable'])) {            $query .= ' DEFERRABLE';        } else {            $query .= ' NOT DEFERRABLE';        }        if (!empty($definition['initiallydeferred'])) {            $query .= ' INITIALLY DEFERRED';        } else {            $query .= ' INITIALLY IMMEDIATE';        }        return $query;    }    // }}}    // {{{ truncateTable()    /**     * Truncate an existing table (if the TRUNCATE TABLE syntax is not supported,     * it falls back to a DELETE FROM TABLE query)     *     * @param string $name name of the table that should be truncated     * @return mixed MDB2_OK on success, a MDB2 error on failure     * @access public     */    function truncateTable($name)    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $name = $db->quoteIdentifier($name, true);        return $db->exec("TRUNCATE TABLE $name");    }    // }}}    // {{{ vacuum()    /**     * Optimize (vacuum) all the tables in the db (or only the specified table)     * and optionally run ANALYZE.     *     * @param string $table table name (all the tables if empty)     * @param array  $options an array with driver-specific options:     *               - timeout [int] (in seconds) [mssql-only]     *               - analyze [boolean] [pgsql and mysql]     *               - full [boolean] [pgsql-only]     *               - freeze [boolean] [pgsql-only]     *     * @return mixed MDB2_OK success, a MDB2 error on failure     * @access public     */    function vacuum($table = null, $options = array())    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $query = 'VACUUM';        if (!empty($options['full'])) {            $query .= ' FULL';        }        if (!empty($options['freeze'])) {            $query .= ' FREEZE';        }        if (!empty($options['analyze'])) {            $query .= ' ANALYZE';        }        if (!empty($table)) {            $query .= ' '.$db->quoteIdentifier($table, true);        }        return $db->exec($query);    }    // }}}    // {{{ alterTable()    /**     * alter an existing table     *     * @param string $name         name of the table that is intended to be changed.     * @param array $changes     associative array that contains the details of each type     *                             of change that is intended to be performed. The types of     *                             changes that are currently supported are defined as follows:     *     *                             name     *     *                                New name for the table.     *     *                            add     *     *                                Associative array with the names of fields to be added as     *                                 indexes of the array. The value of each entry of the array     *                                 should be set to another associative array with the properties     *                                 of the fields to be added. The properties of the fields should     *                                 be the same as defined by the MDB2 parser.     *     *     *                            remove     *     *                                Associative array with the names of fields to be removed as indexes     *                                 of the array. Currently the values assigned to each entry are ignored.     *                                 An empty array should be used for future compatibility.     *     *                            rename     *     *                                Associative array with the names of fields to be renamed as indexes     *                                 of the array. The value of each entry of the array should be set to     *                                 another associative array with the entry named name with the new     *                                 field name and the entry named Declaration that is expected to contain     *                                 the portion of the field declaration already in DBMS specific SQL code     *                                 as it is used in the CREATE TABLE statement.     *     *                            change     *     *                                Associative array with the names of the fields to be changed as indexes     *                                 of the array. Keep in mind that if it is intended to change either the     *                                 name of a field and any other properties, the change array entries     *                                 should have the new names of the fields as array indexes.     *     *                                The value of each entry of the array should be set to another associative     *                                 array with the properties of the fields to that are meant to be changed as     *                                 array entries. These entries should be assigned to the new values of the     *                                 respective properties. The properties of the fields should be the same     *                                 as defined by the MDB2 parser.     *     *                            Example     *                                array(

⌨️ 快捷键说明

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