Home > Backend Development > PHP Tutorial > A relatively simple way to import the sql file generated by phpmyadmin in php_PHP tutorial

A relatively simple way to import the sql file generated by phpmyadmin in php_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:27:30
Original
904 people have browsed it

We know that many forums or personal blog programs downloaded from the Internet have installation pages. To make such an installation program, you need to use a sql file to create a database.

Only valid for sql files exported by phpmyadmin

Copy code The code is as follows:

$dbfile=" test.sql";
$content=iconv("UTF-8","GB2312",file_get_contents($dbfile));
//Get the created data
//Remove the 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_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/323751.htmlTechArticleWe know that many forums or personal blog programs downloaded online have installation pages, so we need to make such an installation program. You need to use sql files to create the database. Only export to phpmyadmin...
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template