Home Backend Development PHP Tutorial 一般PHP系统的网站,安装时往数据库里建表如何操作

一般PHP系统的网站,安装时往数据库里建表如何操作

Jun 13, 2016 pm 01:34 PM
default NOT null query

一般PHP系统的网站,安装时往数据库里建表怎么操作?
比如我已经有了123.sql文件

现在想弄一个安装页面,点提交就将123.sql导入到指定的表中

代码怎么写?


------解决方案--------------------
query(文件内容);
------解决方案--------------------

PHP code
<?php if(...){//判断提交

    //连接数据库...

    $path="./123.sql";//123.sql相对该php文件地址
    mysql_query("source $path");
}
<br /><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨

这么简单?我考虑太多了,汗……

------解决方案--------------------
真的可以这样做吗?
不要自欺欺人了
------解决方案--------------------
找一个安装程序的开源项目,安装一下不就知道了。
dedecms的,一看就明了

大概如下
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 '600',
`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 '200',
`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 
                 
              
              
        
            
Copy after login
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to reorder multiple columns in Power Query via drag and drop How to reorder multiple columns in Power Query via drag and drop Mar 14, 2024 am 10:55 AM

In this article, we will show you how to reorder multiple columns in PowerQuery by dragging and dropping. Often, when importing data from various sources, columns may not be in the desired order. Reordering columns not only allows you to arrange them in a logical order that suits your analysis or reporting needs, it also improves the readability of your data and speeds up tasks such as filtering, sorting, and performing calculations. How to rearrange multiple columns in Excel? There are many ways to rearrange columns in Excel. You can simply select the column header and drag it to the desired location. However, this approach can become cumbersome when dealing with large tables with many columns. To rearrange columns more efficiently, you can use the enhanced query editor. Enhancing the query

React Query database plug-in: how to import and export data React Query database plug-in: how to import and export data Sep 26, 2023 pm 05:37 PM

ReactQuery database plug-in: Methods to implement data import and export, specific code examples are required. With the widespread application of ReactQuery in front-end development, more and more developers are beginning to use it to manage data. In actual development, we often need to export data to local files or import data from local files into the database. In order to implement these functions more conveniently, you can use the ReactQuery database plug-in. The ReactQuery database plugin provides a series of methods

What do undefined and null mean? What do undefined and null mean? Nov 20, 2023 pm 02:39 PM

In JavaScript, both undefined and null represent the concept of "nothing": 1. undefined represents an uninitialized variable or a non-existent property. When a variable is declared but no value is assigned to it, the value of the variable is undefined , when accessing properties that do not exist in the object, the returned value is also undefined; 2. null represents an empty object reference. In some cases, the object reference can be set to null to release the memory it occupies.

What is the difference between null and NULL in c language What is the difference between null and NULL in c language Sep 22, 2023 am 11:48 AM

The difference between null and NULL in C language is: null is a macro definition in C language, usually used to represent a null pointer, which can be used to initialize pointer variables, or to determine whether the pointer is null in a conditional statement; NULL is a macro definition in C language A predefined constant in , usually used to represent a null value, used to represent a null pointer, null pointer array or null structure pointer.

What is the difference between null and undefined What is the difference between null and undefined Nov 08, 2023 pm 04:43 PM

The difference between null and undefined is: 1. Semantic meaning; 2. Usage scenarios; 3. Comparison with other values; 4. Relationship with global variables; 5. Relationship with function parameters; 6. Nullability check; 7. Performance considerations; 8. Performance in JSON serialization; 9. Relationship with types. Detailed introduction: 1. Semantic meaning, null usually means knowing that this variable will not have any valid object value, while undefined usually means that the variable has not been assigned a value, or the object does not have this attribute; 2. Usage scenarios, etc.

When to use null and undefined When to use null and undefined Nov 13, 2023 pm 02:11 PM

Both null and undefined indicate a lack of value or an undefined state. Depending on the usage scenario, there are some guiding principles for choosing to use null or undefined: 1. When you need to clearly indicate that a variable is empty or invalid, you can use null; 2. When a variable has been declared but not yet assigned a value, it will be set to undefined by default; 3. When you need to check whether a variable is empty or undefined, use the strict equality operator "===" to determine whether the variable is null or undefined. .

How to split data to NTFS using Power Query How to split data to NTFS using Power Query Mar 15, 2024 am 11:00 AM

This article will introduce how to use PowerQuery to split data into rows. When exporting data from other systems or sources, it is common to encounter situations where the data is stored in cells combining multiple values. With PowerQuery, we can easily split such data into rows, making the data easier to process and analyze. This can happen if the user doesn't understand Excel's rules and accidentally enters multiple data into a cell, or if the data is not formatted correctly when copying/pasting it from other sources. Processing this data requires additional steps to extract and organize the information for analysis or reporting. How to split data in PowerQuery? PowerQuery transformations can be based on a variety of different factors such as word

How to configure default gateway How to configure default gateway Dec 07, 2023 am 11:34 AM

Steps to configure default gateway: 1. Determine the IP address of the router; 2. Open the network configuration interface of the computer; 3. Configure network connection; 4. Configure IPv4 settings; 5. Enter the IP address and subnet mask; 6. Configure the default gateway ;7. Configure DNS server; 8. Save settings. Detailed introduction: 1. Determine the router's IP address. The default gateway address is usually the router's IP address. You can find the router's IP address on the back of the router or in the user manual; 2. Open the computer's network configuration, etc.

See all articles