Use PHP to execute SQL files, import SQL files into the database,
How to use PHP to automate. sql files is to get the contents of the SQL file and then execute each sentence of the SQL statement at once.
code example:
// Read file contents $_sql = file_get_contents ('test.sql'= explode ('; ' New mysqli (db_host,db_user,db_pass); if (Mysqli_connect_errno ()) { exit (' Error connecting database ');} // Execute SQL statement foreach as $_value) { $_mysqli->query ($_value.' ) ; ' );} $_mysqli,null;
Above text.sql is the SQL file you need to execute, db_host hostname, db_user username, db_pass password!
This is just the most basic automated SQL file, you can also customize the name of the build database by deleting the following code in the SQL file
CREATE database IF not EXISTS db name DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci; Use database name
Plus
$_mysqli->query ("CREATE database IF not EXISTS" name DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci;
"); $_mysqli->query ("usedatabase name ");
http://www.bkjia.com/PHPjc/1107663.html www.bkjia.com true http://www.bkjia.com/PHPjc/1107663.html techarticle using PHP to execute SQL files, import SQL files into the database, how to use PHP to automate the. sql file, is to get the contents of the SQL file, and then each sentence of SQL statement execution. to be a substitute for ...