Php imports phpmyadmin to generate SQL files. Share my methods. Only the SQL file exported by myadmin in the php Tutorial is valid $ dbfiletest. SQL; $ contenticonv (UTF-8, gb2312, file_get_contents ($ dbfile); obtain the created data and share my methods. Only valid for SQL files exported by myadmin in the php Tutorial
$ Dbfile = "test. SQL ";
$ Content = iconv ("UTF-8", "gb2312", file_get_contents ($ dbfile ));
// Obtain the created data
// Remove comments
$ Content = preg_replace ("/--. * n/iu", "", $ content );
// Replace the prefix
$ Content = str_replace ("ct _", table_pre, $ content );
$ Carr = array ();
$ Iarr = array ();
// Extract create
Preg_match_all ("/create table. * (. *). *;/ius", $ content, $ carr );
$ Carr = $ carr [0];
Foreach ($ carr as $ c)
{
@ Mysql tutorial _ query ($ c, $ link );
}
// Extract insert
Preg_match_all ("/insert into. * (. *);/ius", $ content, $ iarr );
$ Iarr = $ iarr [0];
// Insert data
Foreach ($ iarr as $ c)
{
@ Mysql_query ($ c, $ link );
}
Compile the method I used. Only valid for SQL files exported by myadmin in the php Tutorial $ dbfile = test. SQL; $ content = iconv (UTF-8, gb2312, file_get_contents ($ dbfile); // Obtain the created data...