I made a php program to add form data to the database. I used the mysql extension library function to perform operations on the mysql database to add, delete, update, and query words. The running environment is a common mysql database, php, and Apache server. This program is very simple and belongs to a program that can be understood at a Glance. However, we still need to remind you that the database and data table must exist in advance! The database used in this article is test, Data RepresentationTestThe table name in the databaseDanciData Table, which has three attributes: id danci dt: int, char, and timestamp. Directly paste the Code:
The following page is displayed:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
PHP file for processing form data:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
The PHP file of the Database Class is encapsulated:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Database creation functions:
Function createDataBase () {// create a data table $ link = mysql_connect ('localhost', "root", $ password); // you must use the root account and password to log on to if (! $ Link) {die ('could not connect :'. mysql_error ();} $ SQL = 'create DATABASE my_db '; if (mysql_query ($ SQL, $ link) {echo "Database my_db created successfully \ n ";} else {echo 'error creating database :'. mysql_error (). "\ n" ;}mysql_close ($ link );}
Delete database functions:
Function deleteDataBase () {// delete a data table $ link = mysql_connect ('localhost', "root", $ password); // you must use the root account and password to log on to if (! $ Link) {die ('could not connect :'. mysql_error ();} $ SQL = 'drop DATABASE discuz'; if (mysql_query ($ SQL, $ link) {echo "Database discuz droped successfully \ n ";} else {echo 'error droping database :'. mysql_error (). "\ n" ;}mysql_close ($ link );}