Home  >  Article  >  Backend Development  >  PHP automatically installs the .sql file of mysql_PHP tutorial

PHP automatically installs the .sql file of mysql_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:43:32839browse

在做一个安装程序时,一起在想这个安装程序是怎么把SQL文件安装到数据库中的,其时我也知道它是通过文件处理来完成的:
主要就是对文件读取来进行过滤,进而调用数据库的执行语句来完成,即可
以下是SQL语句

--------------------------------------------------------
表的结构cms_album ,该表用于
--------------------------------------------------------
DROP TABLE IF EXISTScms_album;
CREATE TABLE cms_album (......DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
--------------------------------------------------------
表的结构cms_article,该表用于
--------------------------------------------------------
......
很明显,我们需要把SQL语句中的”#,--”等符号去掉即可,再来调用数据库执行语句,mysql_query()等。

php

//Read out all lines
$lines=file ("lampcms.sql"); $sqlstr="";
foreach($lines as $line){

$line=trim($line);
if($line!=""){
>(!($line{0}=="#" || $line{0}.$line{1}=="--")){ // The first two characters at the beginning of $line{0}.$line{1}. PHP strings are available as arrays.
http://www.bkjia.com/PHPjc/478831.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/478831.htmlTechArticleWhen I was making an installation program, I was thinking about how the installation program installed the SQL file into the database. At that time, I also knew that it was done through file processing: mainly...

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