The simplest PHP statement to import a database *.sql file into the database
Copy CodeThe code is as follows:
$sql =file_get_contents ("Text.sql"); Reads SQL statements into $sql as strings
$a =explode (";", $sql); Use the explode () function to put the $sql string ";" Split into arrays
foreach ($a as $b) {//traversal array
$c = $b. ";"; After splitting there is no ";" Because the SQL statement is ";" End, so add it before executing the SQL
mysql_query ($c); Execute SQL statement
}
In many installers you will see the installation of the database, the other mysterious behind is such a simple few lines of code. First, the installation will have a SQL file, and then follow the above code in PHP execution.
http://www.bkjia.com/PHPjc/765158.html www.bkjia.com true http://www.bkjia.com/PHPjc/765158.html techarticle The simplest PHP statement to import the database *.sql file into the database copy code code is as follows: $sql =file_get_contents ("Text.sql");//Read the SQL statement as a string into the $sql $a =explode (";" $sql );...