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

📄 mssql.php

📁 开源邮件管理系统
💻 PHP
📖 第 1 页 / 共 3 页
字号:
                $pk_name  = strtolower($pk_name);            } else {                $key_name = strtoupper($key_name);                $pk_name  = strtoupper($pk_name);            }        }        $table = $db->quote($table, 'text');        $query = "EXEC sp_statistics @table_name=$table";        $indexes = $db->queryCol($query, 'text', $key_name);        if (PEAR::isError($indexes)) {            return $indexes;        }        $query = "EXEC sp_pkeys @table_name=$table";        $pk_all = $db->queryCol($query, 'text', $pk_name);        $result = array();        foreach ($indexes as $index) {            if (!in_array($index, $pk_all) && ($index = $this->_fixIndexName($index))) {                $result[$index] = true;            }        }        if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {            $result = array_change_key_case($result, $db->options['field_case']);        }        return array_keys($result);    }    // }}}    // {{{ listDatabases()    /**     * list all databases     *     * @return mixed array of database names on success, a MDB2 error on failure     * @access public     */    function listDatabases()    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $result = $db->queryCol('SELECT name FROM sys.databases');        if (PEAR::isError($result)) {            return $result;        }        if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {            $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);        }        return $result;    }    // }}}    // {{{ listUsers()    /**     * list all users     *     * @return mixed array of user names on success, a MDB2 error on failure     * @access public     */    function listUsers()    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $result = $db->queryCol('SELECT DISTINCT loginame FROM master..sysprocesses');        if (PEAR::isError($result) || empty($result)) {            return $result;        }        foreach (array_keys($result) as $k) {            $result[$k] = trim($result[$k]);        }        return $result;    }    // }}}    // {{{ listFunctions()    /**     * list all functions in the current database     *     * @return mixed array of function names on success, a MDB2 error on failure     * @access public     */    function listFunctions()    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $query = "SELECT name                    FROM sysobjects                   WHERE objectproperty(id, N'IsMSShipped') = 0                    AND (objectproperty(id, N'IsTableFunction') = 1                     OR objectproperty(id, N'IsScalarFunction') = 1)";        /*        SELECT ROUTINE_NAME          FROM INFORMATION_SCHEMA.ROUTINES         WHERE ROUTINE_TYPE = 'FUNCTION'        */        $result = $db->queryCol($query);        if (PEAR::isError($result)) {            return $result;        }        if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {            $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);        }        return $result;    }    // }}}    // {{{ listTableTriggers()    /**     * list all triggers in the database that reference a given table     *     * @param string table for which all referenced triggers should be found     *     * @return mixed array of trigger names on success,  otherwise, false which     *               could be a db error if the db is not instantiated or could     *               be the results of the error that occured during the     *               querying of the sysobject module.     * @access public     */    function listTableTriggers($table = null)    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $table = $db->quote($table, 'text');        $query = "SELECT o.name                    FROM sysobjects o                   WHERE xtype = 'TR'                     AND OBJECTPROPERTY(o.id, 'IsMSShipped') = 0";        if (!is_null($table)) {            $query .= " AND object_name(parent_obj) = $table";        }        $result = $db->queryCol($query);        if (PEAR::isError($result)) {            return $result;        }        if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE &&            $db->options['field_case'] == CASE_LOWER)        {            $result = array_map(($db->options['field_case'] == CASE_LOWER ?                'strtolower' : 'strtoupper'), $result);        }        return $result;    }    // }}}    // {{{ listViews()    /**     * list all views in the current database     *     * @param string database, the current is default     *     * @return mixed array of view names on success, a MDB2 error on failure     * @access public     */    function listViews()    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $query = "SELECT name                    FROM sysobjects                   WHERE xtype = 'V'";        /*        SELECT *          FROM sysobjects         WHERE objectproperty(id, N'IsMSShipped') = 0           AND objectproperty(id, N'IsView') = 1        */        $result = $db->queryCol($query);        if (PEAR::isError($result)) {            return $result;        }        if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE &&            $db->options['field_case'] == CASE_LOWER)        {            $result = array_map(($db->options['field_case'] == CASE_LOWER ?                          'strtolower' : 'strtoupper'), $result);        }        return $result;    }    // }}}    // {{{ dropIndex()    /**     * drop existing index     *     * @param string $table name of table that should be used in method     * @param string $name  name of the index to be dropped     *     * @return mixed MDB2_OK on success, a MDB2 error on failure     * @access public     */    function dropIndex($table, $name)    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $table = $db->quoteIdentifier($table, true);        $name = $db->quoteIdentifier($db->getIndexName($name), true);        return $db->exec("DROP INDEX $table.$name");    }    // }}}    // {{{ listTableConstraints()    /**     * list all constraints in a table     *     * @param string $table name of table that should be used in method     *     * @return mixed array of constraint names on success, a MDB2 error on failure     * @access public     */    function listTableConstraints($table)    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $table = $db->quoteIdentifier($table, true);        $query = "SELECT c.constraint_name                    FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS c                   WHERE c.constraint_catalog = DB_NAME()                     AND c.table_name = '$table'";        $constraints = $db->queryCol($query);        if (PEAR::isError($constraints)) {            return $constraints;        }        $result = array();        foreach ($constraints as $constraint) {            $constraint = $this->_fixIndexName($constraint);            if (!empty($constraint)) {                $result[$constraint] = true;            }        }        if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {            $result = array_change_key_case($result, $db->options['field_case']);        }        return array_keys($result);    }    // }}}    // {{{ createSequence()    /**     * create sequence     *     * @param string $seq_name name of the sequence to be created     * @param string $start    start value of the sequence; default is 1     *     * @return mixed MDB2_OK on success, a MDB2 error on failure     * @access public     */    function createSequence($seq_name, $start = 1)    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);        $seqcol_name = $db->quoteIdentifier($db->options['seqcol_name'], true);        $query = "CREATE TABLE $sequence_name ($seqcol_name " .                 "INT PRIMARY KEY CLUSTERED IDENTITY($start,1) NOT NULL)";        $res = $db->exec($query);        if (PEAR::isError($res)) {            return $res;        }        $query = "SET IDENTITY_INSERT $sequence_name ON ".                 "INSERT INTO $sequence_name ($seqcol_name) VALUES ($start)";        $res = $db->exec($query);        if (!PEAR::isError($res)) {            return MDB2_OK;        }        $result = $db->exec("DROP TABLE $sequence_name");        if (PEAR::isError($result)) {            return $db->raiseError($result, null, null,                'could not drop inconsistent sequence table', __FUNCTION__);        }        return $db->raiseError($res, null, null,            'could not create sequence table', __FUNCTION__);    }    // }}}    // {{{ dropSequence()    /**     * This function drops an existing sequence     *     * @param string $seq_name name of the sequence to be dropped     *     * @return mixed MDB2_OK on success, a MDB2 error on failure     * @access public     */    function dropSequence($seq_name)    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);        return $db->exec("DROP TABLE $sequence_name");    }    // }}}    // {{{ listSequences()    /**     * list all sequences in the current database     *     * @return mixed array of sequence names on success, a MDB2 error on failure     * @access public     */    function listSequences()    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $query = "SELECT name FROM sysobjects WHERE xtype = 'U'";        $table_names = $db->queryCol($query);        if (PEAR::isError($table_names)) {            return $table_names;        }        $result = array();        foreach ($table_names as $table_name) {            if ($sqn = $this->_fixSequenceName($table_name, true)) {                $result[] = $sqn;            }        }        if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {            $result = array_map(($db->options['field_case'] == CASE_LOWER ?                          'strtolower' : 'strtoupper'), $result);        }        return $result;    }    // }}}}// }}}?>

⌨️ 快捷键说明

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