您现在的位置是:首页 > 教程 > ecshop商城教程ecshop商城教程

完善ecshop的mysql类

以亦2024-12-18 20:56:06ecshop商城教程已有人查阅

导读前篇文章中,我提及到了如何《提取ecshop的mysql类》。但是没有数据库前缀的写法 废话不说,上步骤(目录结构请参考提取ecshop的mysql类)修改connfig.php为

前篇文章中,我提及到了如何《提取ecshop的mysql类》。但是没有数据库前缀的写法 废话不说,上步骤(目录结构请参考提取ecshop的mysql类)修改connfig.php为
<?php
header("Content-Type:text/html;charset=utf-8");
date_default_timezone_set("Etc/GMT-8");
error_reporting(E_ALL ^ E_NOTICE);
global $db;
define('IN_ECS', true);
define('EC_CHARSET', 'utf-8');
define('ROOT_PATH', dirname(__FILE__).'\..\\');
define('DATA_DIR', 'data');
$db_host = "localhost:3306";
$db_name = "duizhang";
$db_user = "root";
$db_pass = "";
$prefix = "mydb_";
require(ROOT_PATH.'Classes/cls_mysql.php');
$db = new cls_mysql($db_host, $db_user, $db_pass, $db_name, $prefix);
?>
修改/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;

本文标签:

很赞哦! ()

留言与评论 (共有 条评论)
验证码:

本栏推荐

相关标签