phpcms v9 评论的bug.

当安装phpcms v9时,如果数据库名称包含大写字母,在发表第二条评论时,会报错:

MySQL Query : CREATE TABLE `jq_comment_data_1` (`id` int(10) unsigned NOT NULL auto_increment,`commentid` char(30) NOT NULL default '',`siteid` smallint(5) NOT NULL default '0',`userid` int(10) unsigned default '0',`username` varchar(20) default NULL,`creat_at` int(10) default 0,`ip` varchar(15) default NULL,`status` tinyint(1) default '0',`content` text,`direction` tinyint(1) default '0',`support` mediumint(8) unsigned default '0',`reply` tinyint(1) NOT NULL default '0',PRIMARY KEY (`id`),KEY `commentid` (`commentid`),KEY `direction` (`direction`), KEY `siteid` (`siteid`),KEY `support` (`support`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;
MySQL Error : Table 'jq_comment_data_1' already exists
MySQL Errno : 1050
Message : Table 'jq_comment_data_1' already exists
Need Help?

 因为这个表已经存在,而程序在判断是否存在时返回不存在,我们来看下代码:

/**
     * 检查表是否存在
     * @param $table 表名
     * @return boolean
     */
    public function table_exists($table) {
        $tables = $this->list_tables();

        return in_array($table, $tables) ? 1 : 0;
    }
    
    public function list_tables() {
        $tables = array();
        $this->execute("SHOW TABLES");
        while($r = $this->fetch_next()) {
            $tables[] = $r['Tables_in_'.$this->config['database']];
        }
        
        return $tables;
    }

在执行SHOW TABLES 返回的字段是 “Tables_in_whaleclub” 而我的数据库配置的数据库名是 WhaleClub,而实际数据库名称也为whaleclub。
解决办法,安装时候不要采用大写字母,修改配置为小写,则可以解决问题。



原文地址:https://www.cnblogs.com/ikodota/p/3068668.html