- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstall_db.php
More file actions
Latest commit
35 lines (31 loc) · 788 Bytes
/
Copy pathinstall_db.php
File metadata and controls
35 lines (31 loc) · 788 Bytes
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>安装数据库</title>
</head>
<body>
</body>
</html>
<?php
//读取文件内容 根目录sql
$_sql = file_get_contents('shop_navicat.sql');
$DB_HOST = "localhost";
$DB_USER = "root";
$DB_PASS = "root";
//根据分号切分sql语句
$_arr = explode(';', $_sql);
$_mysqli = newmysqli($DB_HOST,$DB_USER,$DB_PASS);
if (mysqli_connect_errno()) {
exit('连接数据库出错');
}
//如果数据库不存在就先建立数据库
$_mysqli->query("CREATE DATABASE IF NOT EXISTS shop DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;");
$_mysqli->query("USE shop");
//执行sql语句
foreach ($_arras$_value) {
$_mysqli->query($_value.';');
}
echo'执行成功...';
$_mysqli->close();
$_mysqli = null;