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

📄 mssql.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.                                          |// +----------------------------------------------------------------------+// | Authors: Frank M. Kromann <frank@kromann.info>                       |// |          David Coallier <davidc@php.net>                             |// |          Lorenzo Alberton <l.alberton@quipo.it>                      |// +----------------------------------------------------------------------+//// $Id: mssql.php,v 1.109 2008/03/05 12:55:57 afz Exp $//require_once 'MDB2/Driver/Manager/Common.php';// {{{ class MDB2_Driver_Manager_mssql/** * MDB2 MSSQL driver for the management modules * * @package MDB2 * @category Database * @author  Frank M. Kromann <frank@kromann.info> * @author  David Coallier <davidc@php.net> * @author  Lorenzo Alberton <l.alberton@quipo.it> */class MDB2_Driver_Manager_mssql 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 collation 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 ($db->options['database_device']) {            $query.= ' ON '.$db->options['database_device'];            $query.= $db->options['database_size'] ? '=' .                     $db->options['database_size'] : '';        }        if (!empty($options['collation'])) {            $query .= ' COLLATE ' . $options['collation'];        }        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, collation 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 = '';        if (!empty($options['name'])) {            $query .= ' MODIFY NAME = ' .$db->quoteIdentifier($options['name'], true);        }        if (!empty($options['collation'])) {            $query .= ' COLLATE ' . $options['collation'];        }        if (!empty($query)) {            $query = 'ALTER DATABASE '. $db->quoteIdentifier($name, true) . $query;            return $db->standaloneQuery($query, null, true);        }        return MDB2_OK;    }    // }}}    // {{{ 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);        return $db->standaloneQuery("DROP DATABASE $name", null, true);    }    // }}}    // {{{ _getTemporaryTableQuery()    /**     * Override the parent method.     *     * @return string The string required to be placed between "CREATE" and "TABLE"     *                to generate a temporary table, if possible.     */    function _getTemporaryTableQuery()    {        return '';    }    // }}}    // {{{ _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['onupdate'])) {            $query .= ' ON UPDATE '.$definition['onupdate'];        }        if (!empty($definition['ondelete'])) {            $query .= ' ON DELETE '.$definition['ondelete'];        }        return $query;    }    // }}}    // {{{ createTable()    /**     * create a new table     *     * @param string $name   Name of the database that should be created     * @param array  $fields Associative array that contains the definition of each field of the new table     *                       The indexes of the array entries are the names of the fields of the table an     *                       the array entry values are associative arrays like those that are meant to be     *                       passed with the field definitions to get[Type]Declaration() functions.     *     *                      Example     *                        array(     *     *                            'id' => array(     *                                'type' => 'integer',     *                                'unsigned' => 1,     *                                'notnull' => 1,     *                                'default' => 0,     *                            ),     *                            'name' => array(     *                                'type' => 'text',     *                                'length' => 12,     *                            ),     *                            'description' => array(     *                                'type' => 'text',     *                                'length' => 12,     *                            )     *                        );     * @param array $options An associative array of table options:     *                          array(     *                              'comment' => 'Foo',     *                              'temporary' => true|false,     *                          );     *     * @return mixed MDB2_OK on success, a MDB2 error on failure     * @access public     */    function createTable($name, $fields, $options = array())    {        if (!empty($options['temporary'])) {            $name = '#'.$name;        }        return parent::createTable($name, $fields, $options);    }    // }}}    // {{{ 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]     *     * NB: you have to run the NSControl Create utility to enable VACUUM     *     * @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;        }        $timeout = isset($options['timeout']) ? (int)$options['timeout'] : 300;        $query = 'NSControl Create';        $result = $db->exec($query);        if (PEAR::isError($result)) {            return $result;        }        return $db->exec('EXEC NSVacuum '.$timeout);    }    // }}}    // {{{ 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(     *                                    'name' => 'userlist',     *                                    'add' => array(     *                                        'quota' => array(     *                                            'type' => 'integer',     *                                            'unsigned' => 1     *                                        )     *                                    ),     *                                    'remove' => array(     *                                        'file_limit' => array(),     *                                        'time_limit' => array()     *                                    ),     *                                    'change' => array(     *                                        'name' => array(     *                                            'length' => '20',     *                                            'definition' => array(     *                                                'type' => 'text',     *                                                'length' => 20,     *                                            ),     *                                        )     *                                    ),     *                                    'rename' => array(     *                                        'sex' => array(     *                                            'name' => 'gender',     *                                            'definition' => array(     *                                                'type' => 'text',     *                                                'length' => 1,     *                                                'default' => 'M',     *                                            ),     *                                        )     *                                    )     *                                )

⌨️ 快捷键说明

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