Home > php教程 > php手册 > 使用php语句将数据库*.sql文件导入数据库

使用php语句将数据库*.sql文件导入数据库

WBOY
Release: 2016-06-13 09:35:56
Original
907 people have browsed it

最简单的php语句把数据库*.sql文件导入数据库

复制代码 代码如下:


$sql=file_get_contents("text.sql"); //把SQL语句以字符串读入$sql
$a=explode(";",$sql); //用explode()函数把‍$sql字符串以“;”分割为数组

foreach($a as $b){ //遍历数组
$c=$b.";"; //分割后是没有“;”的,因为SQL语句以“;”结束,所以在执行SQL前把它加上
mysql_query($c); //执行SQL语句
}


在很多安装程序中大家都会看到数据库的安装,其它神秘的背后就是这么简单的几句代码。首先安装中会有一个Sql文件,然后再按照上面的代码在PHP中执行。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template