Home >Backend Development >PHP Tutorial >How to import phpmyadmin to generate sql file_PHP tutorial
Share the method I use. Only valid for sql files exported by php tutorial myadmin
$dbfile="test.sql";
$content=iconv("utf-8","gb2312",file_get_contents($dbfile));
//Get the created data
//Remove comments
$content=preg_replace("/--.*n/iu","",$content);
//Replace 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);
}