Query, deletion, modification, and query of words by php programs based on the mysql database

Source: Internet
Author: User

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




Related Article

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.