How do I create a table in the database during the installation of a PHP website? For example, if I already have the 123. SQL file and want to get an installation page, click submit to import the 123. SQL file to the specified table. how can I write the code ?, Query (file content);, PHPcode & lt ;? Phpif (...) {// determines the website of a common PHP System. how to create a table in the database during installation?
For example, I already have a 123. SQL file.
To get an installation page, click submit to import SQL 123 to the specified table.
How to write code?
------ Solution --------------------
Query (file content );
------ Solution --------------------
PHP code
------ Solution --------------------
Discussion
So simple? I think too much, Khan ......
------ Solution --------------------
Can I do this?
Don't deceive yourself.
------ Solution --------------------
Find an open-source project of the installer and you will not be able to find it after installation.
Dedecms.
Probably as follows:
Sql-dftables.txt
Drop table if exists '# addonarticle ';
Create table '# addonarticle '(
'Aid 'mediumint (8) unsigned not null default '0 ',
'Typeid' smallint (5) unsigned not null default '0 ',
'Body' mediumtext,
'Redirecturl' varchar (255) not null default '',
'Templet' varchar (30) not null default '',
'Userip' char (15) not null default '',
Primary key ('aid '),
KEY 'typeid' ('typeid ')
) TYPE = MyISAM;
Drop table if exists '# addonimages ';
Create table '# addonimages '(
'Aid 'mediumint (8) unsigned not null default '0 ',
'Typeid' smallint (5) unsigned not null default '0 ',
'Pagestyle' smallint (6) not null default '1 ',
'Maxwidth' smallint (6) not null default '20140901 ',
'Imgurls' text,
'Row' smallint (6) not null default '0 ',
'Col' smallint (6) not null default '0 ',
'Isrm 'smallint (6) not null default '0 ',
'Ddmaxwidth' smallint (6) not null default '20140901 ',
'Pagepicnum' smallint (6) not null default '12 ',
'Templet' varchar (30) not null default '',
'Userip' char (15) not null default '',
'Redirecturl' varchar (255) not null default '',
'Body' mediumtext,
Primary key ('aid '),
KEY 'imagesmain' ('typeid ')
) TYPE = MyISAM;
Drop table if exists '# addoninfos ';
Create table '# addoninfos '(
'Aid 'Int (11) not null default '0 ',
'Typeid' int (11) not null default '0 ',
'Channel' smallint (6) not null default '0 ',
'Arcrank 'smallint (6) not null default '0 ',
'Mid 'mediumint (8) unsigned not null default '0 ',
'Click' int (10) unsigned not null default '0 ',
'Title' varchar (60) not null default '',
'Litpic 'varchar (60) not null default '',
'Userip' varchar (15) not null default '',
'Senddate' int (11) not null default '0 ',
'Flag' set ('C', 'H', 'P', 'F', 'S', 'J', 'A', 'B') default NULL,
'Lastpost' int (10) unsigned not null default '0 ',
'Scores' mediumint (8) not null default '0 ',
'Goodpost' mediumint (8) unsigned not null default '0 ',
'Badpost' mediumint (8) unsigned not null default '0 ',
'Nativeplace' smallint (5) unsigned not null default '0 ',
'Infotype' smallint (5) unsigned not null default '0 ',
'Body' mediumtext,
'Endtime' int (11) not null default '0 ',
'Tel 'varchar (50) not null default '',
'Email 'varchar (50) not null default '',
'Address' varchar (100) not null default '',
'Linkman' varchar (50) not null default '',
Primary key ('aid '),
KEY 'typeid' ('typeid', 'nativeplace', 'infotype '),
KEY 'channel' ('channel', 'arcrank ', 'mid', 'click', 'title', 'litpic ', 'senddate', 'Flag ', 'endtime ')
) TYPE = MyISAM;
....
PHP code
$query = ''; $fp = fopen(dirname(__FILE__).'/sql-dftables.txt','r'); while(!feof($fp)) { $line = rtrim(fgets($fp,1024)); if(ereg(";$",$line)) { $query .= $line."\n"; $query = str_replace('#@__',$dbprefix,$query); if($mysqlVersion < 4.1) { $rs = mysql_query($query,$conn); } else { if(eregi('CREATE',$query)) { $rs = mysql_query(eregi_replace('TYPE=MyISAM',$sql4tmp,$query),$conn); } else { $rs = mysql_query($query,$conn); } } $query=''; } else if(!ereg("^(//|--)",$line)) { $query .= $line; } } fclose($fp);