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.
http://www.bkjia.com/PHPjc/765158.htmlwww.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);...