Home >Backend Development >PHP Tutorial >Use php statements to import database *.sql files into the database_PHP tutorial

Use php statements to import database *.sql files into the database_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:30:33945browse

The simplest php statement imports the database *.sql file into the database

Copy the code The code is as follows:

$sql=file_get_contents( "text.sql"); //Read the SQL statement into $sql as a string
$a=explode(";",$sql); //Use the explode() function to read the $sql string as " ;" Split into array

foreach($a as $b){ //Traverse the array
$c=$b.";"; //There is no ";" after splitting, because SQL The statement ends with ";", so add it before executing SQL
mysql_query($c); //Execute SQL statement
}

Everyone will do it in many installation programs Seeing the installation of the database, there are just a few simple lines of code behind the other mystery. First, there will be a Sql file in the installation, and then execute it in PHP according to the above code.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/765158.htmlTechArticleThe simplest php statement imports the database *.sql file into the database. Copy the code as follows: $sql=file_get_contents(" text.sql"); //Read the SQL statement into $sql as a string $a=explode(";",$sql);...
Statement:
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