本文以安装二当家的数据库为例,分为5个步骤,即安装许可协议、运行环境检测、安装参数设置、安装详细过程、安装完成,跳转到后台。
0、请不要问“在不在”之类的问题,有问题直接问!1、学生或暂时没有工作的童鞋,整站资源免费下载!2、¥9.9充值终身VIP会员,加我微信,826096331 拉你进VIP群学习!3、程序员加油,技术改变世界。在线 充值
首先我们看下数据库安装表材料erdangjiade.sql和erdangjiade_data.sql
创建表结构erdangjiade.sql
CREATE TABLE IF NOT EXISTS `meal_accounts` (
`id` int(5) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`name2` varchar(30) NOT NULL,
`key` varchar(50) NOT NULL,
`secret` varchar(50) NOT NULL,
`code` varchar(30) NOT NULL,
`ord` int(6) NOT NULL,
`is_check` tinyint(1) NOT NULL,
`logo` varchar(100) DEFAULT NULL,
`cla` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
插入数据表erdangjiade_data.sql
INSERT INTO `meal_accounts` (`id`, `name`, `name2`, `key`, `secret`, `code`, `ord`, `is_check`, `logo`, `cla`) VALUES
(1, 'qq', 'QQ登陆', '100433042', 'dd3134e26321bce95a446d659ef0020f', 'qq', 1, 0, 'Public/images/top_qq.png', 'login-type4'),
(2, 'sina', '新浪微博登陆', '4264169412', '9ae7ccc2dc16a4942596ce95bfa64e51', 'sina', 2, 0, 'Public/images/top_weibo.png', 'login-type2'),
(3, 'renren', '人人网登陆', '0cb72f1d2d7942a1aad79c33cbce4e1a', '992b87a8217445a2b43c8f14cb65139d', 'renren', 3, 0, 'Public/images/top_renren.png', 'login-type3');
index.php步骤2:运行环境检测
$phpv = @phpversion();
$os = PHP_OS;
$os = php_uname();
$tmp = function_exists('gd_info') ? gd_info() : array();
$server = $_SERVER["SERVER_SOFTWARE"];
$host = (empty($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_HOST"] : $_SERVER["SERVER_ADDR"]);
$name = $_SERVER["SERVER_NAME"];
$max_execution_time = ini_get('max_execution_time');
$allow_reference = (ini_get('allow_call_time_pass_reference') ? '<font color=green>[√]On</font>': '<font color=red>[×]Off</font>');
$allow_url_fopen = (ini_get('allow_url_fopen') ? '<font color=green>[√]On</font>': '<font color=red>[×]Off</font>');
$safe_mode = (ini_get('safe_mode') ? '<font color=red>[×]On</font>': '<font color=green>[√]Off</font>');
$err = 0;
if (empty($tmp['GD Version'])) {
$gd = '<font color=red>[×]Off</font>';
$err++;
} else {
$gd = '<font color=green>[√]On</font> '.$tmp['GD Version'];
}
if (function_exists('mysql_connect')) {
$mysql = '<font color=green>[√]On</font>';
} else {
$mysql = '<font color=red>[×]Off</font>';
$err++;
}
if (ini_get('file_uploads')) {
$uploadSize = '<font color=green>[√]On</font> 文件限制:'.ini_get('upload_max_filesize');
} else {
$uploadSize = '禁止上传';
}
if (function_exists('session_start')) {
$session = '<font color=green>[√]On</font>';
} else {
$session = '<font color=red>[×]Off</font>';
$err++;
}
$folder = array('/', 'Uploads', 'Cache', 'Cache/Cache', 'Cache/Data', 'Cache/Temp', 'Cache/Logs');
include_once("./tmpl/step_2.html");
exit();
检查数据库配置
if ($_GET['testdbpwd']) {
$dbHost = $_POST['dbHost'].':'.$_POST['dbPort'];
$conn = @mysql_connect($dbHost, $_POST['dbUser'], $_POST['dbPwd']);
if ($conn) {
die("1");
} else {
die("");
}
}
$scriptName = !empty($_SERVER["REQUEST_URI"]) ? $scriptName = $_SERVER["REQUEST_URI"] : $scriptName = $_SERVER["PHP_SELF"];
$rootpath = @preg_replace("/\/(I|i)nstall\/index\.php(.*)$/", "", $scriptName);
$domain = empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$domain = $domain.$rootpath;
include_once("./tmpl/step_3.html");
exit();
创建表
//读取数据文件
$sqldata = file_get_contents('./erdangjiade.sql');
$sqlFormat = sql_split($sqldata, $dbPrefix);
/**
执行SQL语句
*/
$counts = count($sqlFormat);
if ($n < $counts) {
$sql = trim($sqlFormat[$n]);
$n++;
if (strstr($sql, 'CREATE TABLE')) {
preg_match('/CREATE TABLE IF NOT EXISTS `([^ ]*)`/', $sql, $matches);
mysql_query("DROP TABLE IF EXISTS `$matches[1]");
$ret = mysql_query($sql);
// print_r($matches);
if ($ret) {
$message = '<font color="gree">成功创建数据表:'.$matches[1].' </font><br />';
} else {
$message = '<font color="red">创建数据表失败:'.$matches[1].' </font><br />';
}
$arr = array('n' = >$n, 'msg' = >$message);
echo json_encode($arr);
exit;
}
}
读取配置文件,替换真实配置数据,并插入数据
//读取配置文件,并替换真实配置数据
$strConfig = file_get_contents('./db.php');
$strConfig = str_replace('#DB_HOST#', $dbHost, $strConfig);
$strConfig = str_replace('#DB_NAME#', $dbName, $strConfig);
$strConfig = str_replace('#DB_USER#', $dbUser, $strConfig);
$strConfig = str_replace('#DB_PWD#', $dbPwd, $strConfig);
$strConfig = str_replace('#DB_PORT#', $dbPort, $strConfig);
// $strConfig = str_replace('#DB_PREFIX#', $dbPrefix, $strConfig);
@file_put_contents('../Application/Common/Conf/config.php', $strConfig);
//插入管理员
$admin_pwd = md5($admin_pwd);
$admin_last_time = $_SERVER['REQUEST_TIME'];
$admin_last_ip = ip2long(get_client_ip());
$query = "INSERT INTO `{$dbPrefix}admin_user` (`name`,`pwd`,`truename`,`email`,`last_login`,`last_ip`) VALUES('$admin_name','$admin_pwd','超级管理员','$site_email','$admin_last_time','$admin_last_ip')";
mysql_query($query);
$message = '成功添加管理员<br/>成功写入配置文件<br/>安装完成.';
$arr = array('n' = >999999, 'msg' = >$message);
echo json_encode($arr);
友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群