Home  >  Article  >  Backend Development  >  How to import phpmyadmin to generate sql file_PHP tutorial

How to import phpmyadmin to generate sql file_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:05:46729browse

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);
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630757.htmlTechArticleShare 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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn