Commit 15dcf008 authored by wolfocde's avatar wolfocde

update

parent bfbcdef1
......@@ -15,7 +15,9 @@ class InstallCheck implements MiddlewareInterface
{
public function process(Request $request, callable $handler): Response
{
$lock_file = base_path() . DIRECTORY_SEPARATOR . 'extend' . DIRECTORY_SEPARATOR . 'install.lock';
$base_path = base_path() . DIRECTORY_SEPARATOR . 'extend' . DIRECTORY_SEPARATOR;
$lock_file = $base_path . 'install.lock';
$sql_data = $base_path . 'm_blog.sql';
if (!file_exists($lock_file)) {
$dbHost = env('db_host');
$dbUser = env('db_username');
......@@ -33,6 +35,19 @@ class InstallCheck implements MiddlewareInterface
return response($errorMsg, 400);
}
}
if (file_exists($sql_data)) {
$sql = file_get_contents($sql_data);
if (!mysqli_select_db($conn, $dbName)) {
$errorMsg = "数据表{$dbName}不存在!";
return response($errorMsg, 400);
}
$exp = array_filter(explode('INSERT INTO', ($sql)));
foreach ($exp as $key => $value) {
$query_sql = 'INSERT INTO ' . htmlspecialchars_decode($value);
$result = mysqli_query($conn, $query_sql);
}
mysqli_close($conn);
}
} catch (\Exception $e) {
$errorMsg = "连接 MySQL 失败: " . mysqli_connect_error() . $e->getMessage();
return response($errorMsg, 400);
......
SET
FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS `article`;
CREATE TABLE `article`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(100) NOT NULL DEFAULT '',
`desc` varchar(255) NOT NULL DEFAULT '',
`c_id` int(10) unsigned NOT NULL DEFAULT '0',
`img` varchar(255) NOT NULL DEFAULT '',
`content` longtext,
`article_date` date DEFAULT NULL,
`click` int(10) unsigned NOT NULL DEFAULT '0',
`status` tinyint(3) unsigned NOT NULL DEFAULT '1',
`sort` int(10) unsigned NOT NULL DEFAULT '0',
`c_time` datetime DEFAULT NULL,
`u_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
KEY `c_id` (`c_id`) USING BTREE,
KEY `article_time` (`article_date`) USING BTREE,
KEY `status` (`status`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
DROP TABLE IF EXISTS `banner`;
CREATE TABLE `banner`
(
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(75) NOT NULL DEFAULT '',
`link` varchar(255) NOT NULL DEFAULT '',
`target` tinyint(3) unsigned NOT NULL DEFAULT '0',
`desc` varchar(255) NOT NULL DEFAULT '',
`img` varchar(255) NOT NULL DEFAULT '',
`status` tinyint(3) unsigned NOT NULL DEFAULT '1',
`c_time` datetime DEFAULT NULL,
`u_time` datetime DEFAULT NULL,
`sort` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`) USING BTREE,
KEY `type` (`target`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
DROP TABLE IF EXISTS `category`;
CREATE TABLE `category`
(
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(30) NOT NULL DEFAULT '',
`status` tinyint(3) unsigned NOT NULL DEFAULT '1',
`c_time` datetime DEFAULT NULL,
`u_time` datetime DEFAULT NULL,
`sort` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`) USING BTREE,
KEY `status` (`status`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
DROP TABLE IF EXISTS `options`;
CREATE TABLE `options`
(
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`type` varchar(30) NOT NULL DEFAULT '',
`content` json DEFAULT NULL,
`status` tinyint(3) unsigned NOT NULL DEFAULT '1',
`c_time` datetime DEFAULT NULL,
`u_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `type` (`type`) USING BTREE,
KEY `status` (`status`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
DROP TABLE IF EXISTS `system_admin`;
CREATE TABLE `system_admin`
(
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(64) NOT NULL DEFAULT '',
`password` varchar(125) NOT NULL DEFAULT '',
`salt` char(6) NOT NULL DEFAULT '',
`date_v` date DEFAULT NULL,
`status` tinyint(3) unsigned NOT NULL DEFAULT '1',
`c_time` datetime DEFAULT NULL,
`u_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `username` (`username`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment