前篇文章中,我提及到了如何《》。但是没有数据库前缀的写法
废话不说,上步骤(目录结构请参考)
修改connfig.php为
修改/Classes/cls_mysql.php
搜索var $timezone,在下面添加
var $db_name = ''; var $prefix = '';
搜索function __construct,修改为(注意红色字体)
function __construct($dbhost, $dbuser, $dbpw, $dbname = '', $prefix = '', $charset = 'gbk', $pconnect = 0, $quiet = 0) { $this->db_name = $dbname; $this->prefix = $prefix; $this->cls_mysql($dbhost, $dbuser, $dbpw, $dbname, $prefix, $charset, $pconnect, $quiet); }
搜索function cls_mysql,修改为(注意红色字体)
function cls_mysql($dbhost, $dbuser, $dbpw, $dbname = '', $prefix = '', $charset = 'gbk', $pconnect = 0, $quiet = 0)
搜索'dbname' => $dbname, 在下面添加
'prefix' => $prefix,
搜索function select_database,在上面添加
function table($str) { return '`' . $this->db_name . '`.`' . $this->prefix . $str . '`'; }
修改完毕。测试即可
$sql = 'SELECT * FROM '.$db->table('member').' WHERE 1';echo $sql;exit;