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

📄 table.class.php

📁 WEBGAME源码,有架设说明,只是非常简单
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php/* $Id: Table.class.php 9856 2007-01-21 13:13:42Z lem9 $ */// vim: expandtab sw=4 ts=4 sts=4:class PMA_Table {    /**     * @var string  table name     */    var $name = '';    /**     * @var string  database name     */    var $db_name = '';    /**     * @var string  engine (innodb, myisam, bdb, ...)     */    var $engine = '';    /**     * @var string  type (view, base table, system view)     */    var $type = '';    /**     * @var array   settings     */    var $settings = array();    /**     * @var array errors occured     */    var $errors = array();    /**     * @var array messages     */    var $messages = array();    /**     * Constructor     *     * @param   string  $table_name table name     * @param   string  $db_name    database name     */    function __construct($table_name, $db_name)    {        $this->setName($table_name);        $this->setDbName($db_name);    }    /**     * @see PMA_Table::getName()     */    function __toString()    {        return $this->getName();    }    function getLastError()    {        return end($this->errors);    }    function getLastMessage()    {        return end($this->messages);    }    /**     * sets table anme     *     * @uses    $this->name to set it     * @param   string  $table_name new table name     */    function setName($table_name)    {        $this->name = $table_name;    }    /**     * returns table name     *     * @uses    $this->name as return value     * @param   boolean wether to quote name with backticks ``     * @return  string  table name     */    function getName($quoted = false)    {        if ($quoted) {            return PMA_backquote($this->name);        }        return $this->name;    }    /**     * sets database name for this table     *     * @uses    $this->db_name  to set it     * @param   string  $db_name     */    function setDbName($db_name)    {        $this->db_name = $db_name;    }    /**     * returns database name for this table     *     * @uses    $this->db_name  as return value     * @param   boolean wether to quote name with backticks ``     * @return  string  database name for this table     */    function getDbName($quoted = false)    {        if ($quoted) {            return PMA_backquote($this->db_name);        }        return $this->db_name;    }    /**     * returns full name for table, including database name     *     * @param   boolean wether to quote name with backticks ``     */    function getFullName($quoted = false)    {        return $this->getDbName($quoted) . '.' . $this->getName($quoted);    }    function isView($db = null, $table = null)    {        if (null !== $db && null !== $table) {            return PMA_Table::_isView($db, $table);        }        if (strpos($this->get('TABLE TYPE'), 'VIEW')) {            return true;        }        return false;    }    /**     * sets given $value for given $param     *     * @uses    $this->settings to add or change value     * @param   string  param name     * @param   mixed   param value     */    function set($param, $value)    {        $this->settings[$param] = $value;    }    /**     * returns value for given setting/param     *     * @uses    $this->settings to return value     * @param   string  name for value to return     * @return  mixed   value for $param     */    function get($param)    {        if (isset($this->settings[$param])) {            return $this->settings[$param];        }        return null;    }    /**     * loads structure data     */    function loadStructure()    {        $table_info = PMA_DBI_get_tables_full($this->getDbName(), $this->getName());        if (false === $table_info) {            return false;        }        $this->settings = $table_info;        if ($this->get('TABLE_ROWS') === null) {            $this->set('TABLE_ROWS', PMA_Table::countRecords($this->getDbName(),                $this->getName(), true, true));        }        $create_options = explode(' ', $this->get('TABLE_ROWS'));        // export create options by its name as variables into gloabel namespace        // f.e. pack_keys=1 becomes available as $pack_keys with value of '1'        foreach ($create_options as $each_create_option) {            $each_create_option = explode('=', $each_create_option);            if (isset($each_create_option[1])) {                $this->set($$each_create_option[0], $each_create_option[1]);            }        }    }    /**     * old PHP 4style constructor     *     * @see     PMA_Table::__construct()     */    function PMA_Table($table_name, $db_name)    {        $this->__construct($table_name, $db_name);    }    /**     * Checks if this "table" is a view     *     * @deprecated     * @todo see what we could do with the possible existence of $table_is_view     * @param   string   the database name     * @param   string   the table name     *     * @return  boolean  whether this is a view     *     * @access  public     */    function _isView($db, $table) {        // maybe we already know if the table is a view        if (isset($GLOBALS['tbl_is_view']) && $GLOBALS['tbl_is_view']) {            return true;        }        // old MySQL version: no view        if (PMA_MYSQL_INT_VERSION < 50000) {            return false;        }        // This would be the correct way of doing the check but at least in        // MySQL 5.0.33 it's too slow when there are hundreds of databases        // and/or tables (more than 3 minutes for 400 tables)        /*if (false === PMA_DBI_fetch_value('SELECT TABLE_NAME FROM `information_schema`.`VIEWS` WHERE `TABLE_SCHEMA` = \'' . $db . '\' AND `TABLE_NAME` = \'' . $table . '\';')) {            return false;        } else {            return true;        } */        // A more complete verification would be to check if all columns        // from the result set are NULL except Name and Comment.        // MySQL from 5.0.0 to 5.0.12 returns 'view',        // from 5.0.13 returns 'VIEW'.        $comment = strtoupper(PMA_DBI_fetch_value('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . $table . '\'', 0, 'Comment'));        return ($comment == 'VIEW');    }    /**     * generates column/field specification for ALTER or CREATE TABLE syntax     *     * @todo    move into class PMA_Column     * @todo on the interface, some js to clear the default value when the default     * current_timestamp is checked     * @static     * @param   string  $name       name     * @param   string  $type       type ('INT', 'VARCHAR', 'BIT', ...)     * @param   string  $length     length ('2', '5,2', '', ...)     * @param   string  $attribute     * @param   string  $collation     * @param   string  $null       with 'NULL' or 'NOT NULL'     * @param   string  $default    default value     * @param   boolean $default_current_timestamp  whether default value is     *                                              CURRENT_TIMESTAMP or not     *                                              this overrides $default value     * @param   string  $extra      'AUTO_INCREMENT'     * @param   string  $comment    field comment     * @param   array   &$field_primary list of fields for PRIMARY KEY     * @param   string  $index     * @param   string  $default_orig     * @return  string  field specification     */    function generateFieldSpec($name, $type, $length = '', $attribute = '',        $collation = '', $null = false, $default = '',        $default_current_timestamp = false, $extra = '', $comment = '',        &$field_primary, $index, $default_orig = false)    {        $is_timestamp = strpos(' ' . strtoupper($type), 'TIMESTAMP') == 1;        // $default_current_timestamp has priority over $default        /**         * @todo include db-name         */        $query = PMA_backquote($name) . ' ' . $type;        if ($length != ''            && !preg_match('@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT)$@i', $type)) {            $query .= '(' . $length . ')';        }        if ($attribute != '') {            $query .= ' ' . $attribute;        }        if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($collation)          && $collation != 'NULL'          && preg_match('@^(TINYTEXT|TEXT|MEDIUMTEXT|LONGTEXT|VARCHAR|CHAR|ENUM|SET)$@i', $type)) {            $query .= PMA_generateCharsetQueryPart($collation);        }        if ($null !== false) {            if (!empty($null)) {                $query .= ' NOT NULL';            } else {                $query .= ' NULL';            }        }        if ($default_current_timestamp && $is_timestamp) {            $query .= ' DEFAULT CURRENT_TIMESTAMP';        // auto_increment field cannot have a default value        } elseif ($extra !== 'AUTO_INCREMENT'          && (strlen($default) || $default != $default_orig)) {            if (strtoupper($default) == 'NULL') {                $query .= ' DEFAULT NULL';            } else {                if (strlen($default)) {                    if ($is_timestamp) {                        // a TIMESTAMP does not accept DEFAULT '0'                        // but DEFAULT 0  works                        $query .= ' DEFAULT ' . PMA_sqlAddslashes($default);                    } else {                        $query .= ' DEFAULT \'' . PMA_sqlAddslashes($default) . '\'';                    }                }            }        }        if (!empty($extra)) {            $query .= ' ' . $extra;            // An auto_increment field must be use as a primary key            if ($extra == 'AUTO_INCREMENT' && isset($field_primary)) {                $primary_cnt = count($field_primary);

⌨️ 快捷键说明

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