Super simple php + mysql message source code

Source: Internet
Author: User
Tags php database

3 files in total
IncDB. php database connection
Index. php Homepage
InsetToDB. php database operations
Create a table in the database lguestbook
Copy codeThe Code is as follows:
Create table 'intd '(
'Id' int (11) not null auto_increment,
'Name' varchar (255) character set utf8 collate utf8_bin not null,
'Text' text character set utf8 collate utf8_bin not null,
'Datetime' datetime not null,
Primary key ('id ')
) ENGINE = MyISAM default charset = gb2312 AUTO_INCREMENT = 11; // For more information, see the following extensions;

IncDB. php database connection
Copy codeThe Code is as follows:
<? Php
$ Link = mysql_connect ('localhost', 'root', 'root ');
If (! $ Link)
{
Die ("<center> error: 1! </Center> ");
}
If (! Mysql_select_db ('guestbook', $ link ))
{
Die ("<center> error: 2! </Center> ");
}
?>

Index. php code
Copy codeThe Code is as follows:
<Meta http-equiv = "Content-Type" content = "text/html; charset = gbk">
<? Php
Include ("IncDB. php ");
$ Result = mysql_query ("SELECT * FROM intd", $ link );
$ Row = mysql_fetch_row ($ result );
While ($ row)
{
Echo "ID:". $ row [0]. "name:". $ row [1]. "Time:". $ row [3]. "<br> ";
Echo $ row [2];
Echo "$ Row = mysql_fetch_row ($ result );
}
Mysql_close ($ link );
?>
<Form method = "POST" action = "InsetToDB. php">
Nickname: <input type = "text" size = "8"; name = "name">
<P> content: <textarea rows = "5" name = "text" cols = "60"> </textarea>
</P>
<P> <input type = "submit" value = "submit" name = "B1"> <input type = "reset" value = "reset" name = "B2"> </p>
</Form>

InsetToDB. php code:
Copy codeThe Code is as follows:
<? Php
Include ("IncDB. php ");
$ Name = addslashes ($ _ POST ['name']);
$ Text = addslashes ($ _ POST ['text']);
$ SQL = "INSERT INTO 'int' ('id', 'name', 'text', 'datetime') VALUES (NULL, '$ name',' $ text ', now ());";
// $ SQL = "INSERT INTO 'int' (, 'name', 'text', 'datetime') VALUES (, '$ name',' $ text ', now ())";
If (mysql_query ($ SQL, $ link ))
{
Echo "message successful! ";
Echo "<meta http-equiv = \" refresh \ "content = \" 1; URL = index. php \ "> ";
}
Else
Echo "Message failed! ";
Mysql_close ($ link );
?>

Extended content:
MySQL engine/type InnoDB/MYISAM/MERGE/BDB/HEAP
I have read the MySQL reference manual and found that there are multiple database storage engines in CREATE TABLE:
TYPE = {BDB | HEAP | ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM}
I checked the information on the Internet and it is said that MyISAM and InnoDB are commonly used engines.
The major difference is as follows [I do not know whether it is accurate]:
Advanced processing:
The MyISAM type does not support advanced processing such as transaction processing, whereas the InnoDB type does.
Execution speed:
MyISAM tables emphasize performance, and the execution speed is faster than that of InnoDB tables.
Value shifting:
Binary data files of the MyISAM type can be migrated in different operating systems. That is, it can be copied directly from Windows to linux.
Find the official explanation today
· MyISAM: the default MySQL plug-in storage engine, which is one of the most commonly used storage engines in Web, data warehousing, and other application environments. Note: by changing the STORAGE_ENGINE configuration variables, you can easily change the default storage engine of the MySQL server.
· InnoDB: used for transaction processing applications. It has many features, including ACID transaction support.
· BDB: it can replace InnoDB's transaction engine and support COMMIT, ROLLBACK, and other transaction features.
· Memory: stores all data in RAM and provides extremely fast access in environments where reference and other similar data need to be quickly searched.
· Merge: Allows MySQL DBAs or developers to logically combine a series of equivalent MyISAM tables and reference them as one object. It is suitable for VLDB environments such as data warehousing.
· Archive: provides a perfect solution for storing and retrieving a large number of rarely referenced historical, archived, or security audit information.
· Federated: connects multiple separated MySQL servers and creates a logical database from multiple physical servers. It is very suitable for distributed environments or data mart environments.
· Cluster/NDB: MySQL's Cluster-based database engine is especially suitable for applications with high-performance search requirements. Such search requirements also require the highest normal working time and availability.
· Other: Other storage engines include CSV (referencing files separated by commas as database tables), Blackhole (used to temporarily prohibit database application input ), and the Example engine (which can help you quickly create a custom plug-in storage engine ).
Remember that you do not have to use the same storage engine for the entire server or solution. You can use different storage engines for each table in the solution. This is very important.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.