From 599310dc790e2e6f8385c763cc8a9b656182e14f Mon Sep 17 00:00:00 2001 From: liweisen Date: Fri, 8 May 2020 10:00:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=89=E8=A3=85=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/index/controller/Index.php | 66 +++++++++++++++----------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php index ea12192..2371a7a 100644 --- a/application/index/controller/Index.php +++ b/application/index/controller/Index.php @@ -82,17 +82,25 @@ class Index extends BasicApi } $initData = isset($_POST['initData']) ? $_POST['initData'] : false; - $mysqlHostname = isset($_POST['mysqlHost']) ? $_POST['mysqlHost'] : '127.0.0.1'; - $mysqlHostport = isset($_POST['mysqlHostport']) ? $_POST['mysqlHostport'] : 3306; - $hostArr = explode(':', $mysqlHostname); - if (count($hostArr) > 1) { - $mysqlHostname = $hostArr[0]; - $mysqlHostport = $hostArr[1]; - } - $mysqlUsername = isset($_POST['mysqlUsername']) ? $_POST['mysqlUsername'] : 'root'; - $mysqlPassword = isset($_POST['mysqlPassword']) ? $_POST['mysqlPassword'] : 'root'; - $mysqlDatabase = isset($_POST['mysqlDatabase']) ? $_POST['mysqlDatabase'] : 'pearProject'; - $mysqlPrefix = isset($_POST['mysqlPrefix']) ? $_POST['mysqlPrefix'] : 'pear_'; +// $mysqlHostname = isset($_POST['mysqlHost']) ? $_POST['mysqlHost'] : '127.0.0.1'; +// $mysqlHostport = isset($_POST['mysqlHostport']) ? $_POST['mysqlHostport'] : 3306; +// $hostArr = explode(':', $mysqlHostname); +// if (count($hostArr) > 1) { +// $mysqlHostname = $hostArr[0]; +// $mysqlHostport = $hostArr[1]; +// } +// $mysqlUsername = isset($_POST['mysqlUsername']) ? $_POST['mysqlUsername'] : 'root'; +// $mysqlPassword = isset($_POST['mysqlPassword']) ? $_POST['mysqlPassword'] : 'root'; +// $mysqlDatabase = isset($_POST['mysqlDatabase']) ? $_POST['mysqlDatabase'] : 'pearProject'; +// $mysqlPrefix = isset($_POST['mysqlPrefix']) ? $_POST['mysqlPrefix'] : 'pear_'; + + $mysqlHostname = config('database.hostname'); + $mysqlHostport = config('database.hostport'); + $mysqlUsername = config('database.username'); + $mysqlPassword = config('database.password'); + $mysqlDatabase = config('database.database'); + $mysqlPrefix = config('database.prefix'); + try { ignore_user_abort(); set_time_limit(0); @@ -104,7 +112,7 @@ class Index extends BasicApi $sql = str_replace("`pms_", "`{$mysqlPrefix}", $sql); $pdo = new PDO("mysql:host={$mysqlHostname};port={$mysqlHostport}", $mysqlUsername, $mysqlPassword, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" + PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb" )); //检测是否支持innodb存储引擎 @@ -120,23 +128,23 @@ class Index extends BasicApi $pdo->exec($sql); - $config = @file_get_contents($dbConfigFile); - $callback = function ($matches) use ($mysqlHostname, $mysqlHostport, $mysqlUsername, $mysqlPassword, $mysqlDatabase, $mysqlPrefix) { - $field = ucfirst($matches[1]); - $replace = ${"mysql{$field}"}; - if ($matches[1] == 'hostport' && $mysqlHostport == 3306) { - $replace = ''; - } - return "'{$matches[1]}'{$matches[2]}=>{$matches[3]}'{$replace}',"; - }; - - $config = preg_replace_callback("/'(hostname|database|username|password|hostport|prefix)'(\s+)=>(\s+)(.*),/", $callback, $config); - //检测能否成功写入数据库配置 - $result = @file_put_contents($dbConfigFile, $config); - - if (!$result) { - throw new Exception("无法写入数据库信息到config/database.php文件,请检查是否有写权限"); - } +// $config = @file_get_contents($dbConfigFile); +// $callback = function ($matches) use ($mysqlHostname, $mysqlHostport, $mysqlUsername, $mysqlPassword, $mysqlDatabase, $mysqlPrefix) { +// $field = ucfirst($matches[1]); +// $replace = ${"mysql{$field}"}; +// if ($matches[1] == 'hostport' && $mysqlHostport == 3306) { +// $replace = ''; +// } +// return "'{$matches[1]}'{$matches[2]}=>{$matches[3]}'{$replace}',"; +// }; +// +// $config = preg_replace_callback("/'(hostname|database|username|password|hostport|prefix)'(\s+)=>(\s+)(.*),/", $callback, $config); +// //检测能否成功写入数据库配置 +// $result = @file_put_contents($dbConfigFile, $config); +// +// if (!$result) { +// throw new Exception("无法写入数据库信息到config/database.php文件,请检查是否有写权限"); +// } //检测能否成功写入lock文件 $result = @file_put_contents($lockFile, 1);