php 将sql文件导入数据库
include 'dishedhou.sql';//dishedhou.sql当前目录下的sql文件function insert($file,$database,$name,$root,$pwd){
//将表导入数据库
$_sql = file_get_contents($file);//自己的.sql文件
$_arr = explode(';', $_sql);
$_mysqli = new mysqli($name,$root,$pwd,$database);
if (mysqli_connect_errno()) {
exit('连接数据库出错');
} else{
//执行sql语句
$_mysqli->query('set names utf8;'); //设置编码方式
foreach ($_arr as $_value) {
$_mysqli->query($_value.';');
}
echo "插入成功";
}
$_mysqli->close();
$_mysqli = null;
}
insert("dishedhou.sql",'dishedhou',"localhost","root","root");