PHP processes the SQL script file and imports it to the MySQL code instance. Copy the code as follows :? PhpNameofthefile $ filenamechurch C. SQL; MySQLhost $ mysql_hostlocalhost; MySQLusername $ mysql_usernameroot; MySQLpassword
The code is as follows:
// Name of the file
$ Filename = 'chilc. 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 each line
Foreach ($ lines as $ line)
{
// Skip it if it's a comment
If (substr ($ line, 0, 2) = '--' | $ line = '')
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
Mysql_query ($ templine) or print ('error checking Ming query \''. $ Templine.' \ ':'. mysql_error ().'
');
// Reset temp variable to empty
$ Templine = '';
}
}
Echo "Tables imported successfully ";
?>
The http://www.bkjia.com/PHPjc/742450.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/742450.htmlTechArticle code is as follows :? Php // Name of the file $ filename = 'chilc. SQL '; // MySQL host $ mysql_host = 'localhost'; // MySQL username $ mysql_username = 'root'; // MySQL password...