Super simple PHP +mysql message source code

  • 2020-03-31 16:43:40
  • OfStack

There are three files
Incdb.php database connection
Index.php page
Insettodb.php database operation
The tables are built in the database lguestbook
 
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 following extension;

Incdb.php database connection
 
<?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
 
<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]."  The name : ".$row[1]."  time : ".$row[3]."<br>"; 
echo $row[2]; 
echo "<hr><br>"; 
$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:
 
<?php 
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 "<meta http-equiv="refresh" content="1;URL=index.php">"; 
} 
else 
echo " Message failed! "; 
mysql_close($link); 
?> 

Expanded content:
MySQL engine/InnoDB/MYISAM type type/MERGE/BDB/HEAP
A look at the MySQL reference manual reveals that there are multiple database storage engines for the CREATE TABLE:
TYPE = {BDB | HEAP b| ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM}
Online check it is said that MyISAM, InnoDB two engines commonly used
The difference is as follows:
Advanced processing:
The MyISAM type does not support advanced processing such as transactions, while the InnoDB type does.
Execution speed:
Tables of the MyISAM type emphasize performance and are faster to execute than tables of the InnoDB type.
Shift:
Binary data files of type MyISAM can be migrated between 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 that you can easily change the default storage engine for the MySQL server by changing the STORAGE_ENGINE configuration variable.
, InnoDB: for transaction processing applications, it has a number of features, including ACID transaction support.
, BDB: InnoDB alternative transaction engine, supports COMMIT, ROLLBACK, and other transaction features.
, Memory: all data is stored in RAM, providing extremely fast access in environments where you need to quickly find references and other similar data.
, Merge: allows a MySQL DBA or developer to logically combine a series of equivalent MyISAM tables and reference them as an object. This is ideal for VLDB environments such as data warehousing.
, Archive: a perfect solution for storing and retrieving large amounts of rarely referenced historical, archived, or security audit information.
, Federated: the ability to link multiple separate MySQL servers to create a logical database from multiple physical servers. Ideal for distributed or data mart environments.
, Cluster/NDB: MySQL's Cluster database engine, especially suitable for applications with high performance lookup requirements, which also require the highest uptime and availability.
, Other: Other storage engines include CSV (referring to comma-separated files that are used as database tables), Blackhole (for temporarily disabling application input to a database), and the Example engine (for quickly creating a custom plug-in storage engine).
Remember, you don't have to use the same storage engine for the entire server or schema, it's important that you use a different storage engine for each table in the schema.

Related articles: