usually in the production of the installer, data Backup program will use this code, I think there is not much online, and some are not very good, sometimes this code directly with ready-made can save a lot of time, then I transferred from the StackOverflow a come, Need friends can refer to the following
The code is as follows: <?php //Name of the file $filename = ' churc.sql '; MySQL host $mysql _host = ' localhost '; MySQL username $mysql _username = ' root '; MySQL password $mysql _password = '; Database name $mysql _database = ' dump '; //Connect to MySQL server mysql_connect ($mysql _host, $mysql _username, $mysql _password) or Die (' Error connecting to MySQL server: '. Mysql_error ()); Select database mysql_select_db ($mysql _database) or Die (' Error selecting MySQL database: '. mysql_error ()); //temporary variable, used to store current query $templine = '; Read in entire file $lines = file ($filename); Loop through per line foreach ($lines as $line) {//Skip it if it ' s a comment if (substr ($line, 0, 2) = '--' | | $lin E = = ') continue; //ADD This line to the current segment $templine. = $line; If it has a semicolon at the end, it's the end of the query if (substr (Trim ($line),-1, 1) = = '; ') { //Perform the query &NBSP; mysql_query ($templine) or print (' Error performing query ' <strong> '. $templine. '': ' . Mysql_error (). ' <br/><br/> '); //Reset temp variable to empty $templine = '; } echo "Tables imported successfully";?>