首页 > 代码库 > install.php
install.php
<?php if ( ! defined(‘BASEPATH‘)) exit(‘No direct script access allowed‘);
/**
* 帐户控制器
*/
class Install extends MY_Controller {
public function __construct() {
parent::__construct();
if(file_exists("./data/install.lock")){
header("location:/");
}
// $this->load->model(‘party_model‘, ‘party‘);
$this->load->model(‘common_model‘, ‘common‘);
}
//首页
public function index() {
$this->display(‘install/index‘);
}
public function step4(){
if($_POST){
//创建数据库
$dbconfig[‘DB_TYPE‘]="mysql";
$dbhost=$dbconfig[‘DB_HOST‘]=$_POST[‘dbhost‘];
$dbuser=$dbconfig[‘DB_USER‘]=$_POST[‘dbuser‘];
$dbpw=$dbconfig[‘DB_PWD‘]=$_POST[‘dbpw‘];
$dbname=$dbconfig[‘dbname‘]=strtolower($_POST[‘dbname‘]);
$data=http://www.mamicode.com/‘<?php if ( ! defined(\‘BASEPATH\‘)) exit(\‘No direct script access allowed\‘);
$active_group = \‘default\‘;
$active_record = TRUE;
//DB
$db[\‘default\‘][\‘hostname\‘] = \‘‘.$dbhost.‘\‘;
$db[\‘default\‘][\‘port\‘] = \‘3306\‘;
$db[\‘default\‘][\‘username\‘] = \‘‘.$dbuser.‘\‘;
$db[\‘default\‘][\‘password\‘] = \‘‘.$dbpw.‘\‘;
$db[\‘default\‘][\‘database\‘] = \‘‘.$dbname.‘\‘;
$db[\‘default\‘][\‘dbdriver\‘] = \‘mysql\‘;
$db[\‘default\‘][\‘dbprefix\‘] = \‘\‘;
$db[\‘default\‘][\‘pconnect\‘] = TRUE;
$db[\‘default\‘][\‘db_debug\‘] = FALSE;
$db[\‘default\‘][\‘cache_on\‘] = FALSE;
$db[\‘default\‘][\‘cachedir\‘] = \‘\‘;
$db[\‘default\‘][\‘char_set\‘] = \‘utf8\‘;
$db[\‘default\‘][\‘dbcollat\‘] = \‘utf8_general_ci\‘;
$db[\‘default\‘][\‘swap_pre\‘] = \‘\‘;
$db[\‘default\‘][\‘autoinit\‘] = TRUE;
$db[\‘default\‘][\‘stricton\‘] = FALSE;
‘;
$file_path=APP."/application/config/database.php";
file_put_contents($file_path, $data);
// die;
// $con=@mysql_connect($dbconfig[‘DB_HOST‘],$dbconfig[‘DB_USER‘],$dbconfig[‘DB_PWD‘]);
// $sql = "CREATE DATABASE IF NOT EXISTS `{$dbname}` DEFAULT CHARACTER SET utf8";
// mysql_query($sql);
//
//// echo "<pre>";var_dump($res);exit;
//
// $this->sp_execute_sql($dbconfig,"ych3.sql");
$_SESSION[‘_install_step‘]=4;
//
// sleep(1);
go2("congratulations,you has success!","/install/step5");
}else{
exit;
}
}
function sp_execute_sql($dbconfig,$file){
$con=@mysql_connect($dbconfig[‘DB_HOST‘],$dbconfig[‘DB_USER‘],$dbconfig[‘DB_PWD‘]);
mysql_select_db($dbconfig[‘dbname‘],$con);
//读取SQL文件
$sql = file_get_contents(WEBROOT . ‘/data/‘.$file);
$sql = str_replace("\r", "\n", $sql);
$sql = explode(";\n", $sql);
//echo "<pre>";var_dump($sql);exit;
//替换表前缀
// $default_tablepre = "cmf_";
// $sql = str_replace(" `{$default_tablepre}", " `{$tablepre}", $sql);
//开始安装
// sp_show_msg(‘开始安装数据库...‘);
foreach ($sql as $item) {
$item = trim($item);
if(empty($item)) continue;
@preg_match(‘/CREATE TABLE `([^ ]*)`/‘, $item, $matches);
mysql_query($item);
// if($matches) {
// $table_name = $matches[1];
// $msg = "创建数据表{$table_name}";
// if(false !== mysql_query($item)){
// sp_show_msg($msg . ‘ 完成‘);
// } else {
// sp_show_msg($msg . ‘ 失败!‘, ‘error‘);
// }
// } else {
// mysql_query($item);
//// $db->execute($item);
//
// }
}
mysql_close($con);
}
public function step5(){
if($_SESSION[‘_install_step‘]==4){
@touch(‘./data/install.lock‘);
// $this->view(‘install/step5‘);
$this->display(‘install/step5‘);
}else{
echo "<script>alert(‘非法安装!‘);history.go(-1);</script>";
// history_back();
// $this->error("非法安装!");
}
}
public function testdbpwd()
{
if ($_POST) {
$dbconfig = I("POST.");
$dbconfig[‘DB_TYPE‘] = "mysql";
$db = Db::getInstance($dbconfig);
try {
$db->query("show databases;");
} catch (\Exception $e) {
die("");
}
exit("1");
} else {
exit("need post!");
}
}
}
install.php
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。