-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.php
More file actions
43 lines (39 loc) · 1.28 KB
/
config.php
File metadata and controls
43 lines (39 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
// 安装状态检查 - 只有在访问 install.php 时才检查 install.lock
if (basename($_SERVER['PHP_SELF']) !== 'install.php' && file_exists('install.lock')) {
// 如果是安装文件,不执行重定向
if (basename($_SERVER['PHP_SELF']) !== 'install.php') {
// 检查是否已经存在配置文件
if (!file_exists('config.inc.php')) {
header('Location: install.php');
exit;
}
}
}
// 如果存在配置文件,包含它
if (file_exists('config.inc.php')) {
require 'config.inc.php';
} else {
// 数据库配置默认值(仅在未安装时使用)
define('DB_HOST', 'localhost');
define('DB_USER', 'Your_DB_USER');
define('DB_PASS', 'Password');
define('DB_NAME', 'DBname');
define('DB_TABLE', 'hitokoto');
define('ADMIN_TABLE', 'admin_users');
}
// 创建数据库连接
function db_connect() {
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($conn->connect_error) {
// 如果是安装过程,允许连接失败
if (basename($_SERVER['PHP_SELF']) === 'install.php') {
return $conn;
} else {
die("数据库连接失败: " . $conn->connect_error);
}
}
$conn->set_charset("utf8mb4");
return $conn;
}
?>