Home  >  Article  >  Backend Development  >  Super simple php+mysql guestbook source code_PHP tutorial

Super simple php+mysql guestbook source code_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:42:52836browse

There are 3 files in total
IncDB.php database connection
index.php homepage
InsetToDB.php database operation
Creating tables in database lguestbook

Copy code The 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; //This sentence refers to the expanded content below;

IncDB.php database connection
Copy code Code As follows:

$link=mysql_connect('localhost','root','root');
if(!$link)
{
die("
Error:1!
");
}
if(!mysql_select_db('guestbook',$link))
{
die ("
Error: 2!
");
}
?>

index.php code
Copy code The code is as follows:


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);
?>

Nickname:

Content:





InsetToDB.php code:
Copy code The code is as follows:

include("IncDB.php");
$name=addslashes($_POST['name']);
$text=addslashes($_POST ['text']);
$sql = "INSERT INTO `intd` (`id`, `name`, `text`, `datetime`) VALUES (NULL, '$name', '$text', now());";
//$sql="INSERT INTO `intd` ( , `name` , `text`,`datetime` ) VALUES ( ,'$name','$text',now( ))";
if(mysql_query($sql,$link))
{
echo "Message successful! ";
echo "";
}
else
echo "Message failed! ";
mysql_close($link);
?>

Extended content explanation:
The difference between MySQL engine/type type InnoDB/MYISAM/MERGE/BDB/HEAP
Looking at the MySQL reference manual, I found that there are multiple database storage engines when CREATE TABLE:
TYPE = { BDB | HEAP | ISAM | InnoDB | MERGE| >The MyISAM type does not support advanced processing such as transaction processing, but the InnoDB type does.
Execution speed:
MyISAM type table emphasizes performance, and its execution times are faster than the InnoDB type.
Migration:
MyISAM type binary data files can be migrated in different operating systems. That is to say, it can be copied directly from the Windows system to the Linux system for use.
Find the official and accurate explanation today
· MyISAM: The default MySQL plug-in storage engine, it is one of the most commonly used storage engines in Web, data warehousing and other application environments. Note that the default storage engine of the MySQL server can be easily changed by changing the STORAGE_ENGINE configuration variable.
· InnoDB: For transaction processing applications, with numerous features, including ACID transaction support.
· BDB: A transaction engine that can replace InnoDB, supporting COMMIT, ROLLBACK and other transaction features.
· Memory: Keeps all data in RAM, providing extremely fast access in environments where references and other similar data need to be looked up quickly.
· Merge: Allows a MySQL DBA or developer to logically group together a series of equivalent MyISAM tables and reference them as 1 object. It is very suitable for VLDB environments such as data warehousing.
· Archive: Provides the perfect solution for the storage and retrieval of large amounts of rarely referenced historical, archival, or security audit information.
· Federated: Ability to link multiple separate MySQL servers to create a logical database from multiple physical servers. Very suitable for distributed environments or data mart environments.
· Cluster/NDB: MySQL's clustered database engine, especially suitable for applications with high-performance search requirements that also require the highest uptime and availability.
· Other: Other storage engines include CSV (comma-separated references to files used as database tables), Blackhole (used to temporarily suppress application input to the database), and the Example engine (can be used to quickly create customized Plug-in storage engines help).
It’s important to remember that you don’t have to use the same storage engine for the entire server or scenario, you can use a different storage engine for each table in the scenario.



http://www.bkjia.com/PHPjc/320864.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/320864.htmlTechArticleA total of 3 files IncDB.php database connection index.php home page InsetToDB.php database operation database lguestbook inside create table copy The code is as follows: CREATE TABLE `intd` ( `id` int(11) NOT...
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