PHP executes the SQL file and imports the SQL file to the database,
// Read the file content $ _ SQL = file_get_contents ('test. SQL '); $ _ arr = explode ('; ', $ _ SQL); $ _ mysqli = new mysqli (DB_HOST, DB_USER, DB_PASS); if (mysqli_connect_errno ()) {exit ('database connection error ');} // execute the SQL statement foreach ($ _ arr as $ _ value) {$ _ mysqli-> query ($ _ value. ';') ;}$ _ mysqli-> close (); $ _ mysqli = null;
Text. SQL above is the SQL file you need to execute, DB_HOST host name, DB_USER username, DB_PASS password!
This is only the most basic SQL file for automatic execution. You can also customize the name of the database to delete the code in the SQL file.
Create database if not exists database name default character set utf8 COLLATE utf8_general_ci;
USE Database Name
Add the code before executing all SQL statements in text. php.
$ _ Mysqli-> query ("create database if not exists database name default character set utf8 COLLATE utf8_general_ci;"); $ _ mysqli-> query ("use database Name ");
The above is all the content of this article and I hope it will help you.