Sample code for PHP 5 to manage any database table in MySQL 5 (1 ). Php (as the mainstream development language) 5 + MySQL (the best combination with PHP) 5 + apache (the most popular WEB server platform on the Unix platform) 2 is already the most popular site creation mode. 5 + MySQL (the best combination with php) 5 + apache (the most popular WEB server platform on the Unix platform) 2 is already the most popular site creation mode. It is a little tedious to operate on MySQL (the best combination with PHP) tables only using the SQL language. Therefore, I wrote a set of php (as the mainstream development language) code for adding, deleting, and modifying records to various tables by referring to the code on the Internet. For your reference and entertainment only.
The code below is available in php (as the mainstream development language) 5 + MySQL (the best combination with PHP) 5 + apache (the most popular WEB server platform on Unix) 2 for WinXp.
First, describe the applicability of the code. according to the characteristics of most tables, each table has an id. Therefore, the code applies to the table with the first column id. The name does not matter. it is important that the code performs operations based on the first column of Prima (the most complete VM Management System) ry key by default. There are no other restrictions. this code can operate any column table. Disadvantage: no input review is conducted. Therefore, do not enter blank rows or mismatched types when entering the record. this must be used with the table creation of MySQL (the best combination with PHP.
Note: reminder! When copying the above code, be sure to remove the tab before each line of code in the editor. otherwise, php (as the mainstream development language) 5 cannot be compiled.
In addition, $ database in each file is currently sunsite, and $ table is software, which can be modified as needed.
The first is index. php (as the mainstream development language). The main function is to allow users to enter the table name, and then click the View button to view the table content. It is also the default homepage.
// Index. php (as the mainstream development language)
Admin
Please input the table name
Then tables. php (as the mainstream development language) is used to display the table content. With the entry for adding, deleting, and modifying.
// Tables. php (as the mainstream development language)
Current table
$ Database = "sunsite"
$ Tablename = $ _ REQUEST [tablename];
Echo "Data from $ tablename"
MySQL (best combination with PHP) _ connect ("localhost", "root", "") or die ("Problem connecting to DataBase ");
$ Query = "show columns from $ tablename"
$ Result = MySQL (the best combination with PHP) _ db_query ($ database, $ query );
$ Column = 0;
If ($ result)
{
Echo "Found these entries in the database:
"
Echo"
$ Query = "select * from $ tablename"
$ Result = MySQL (the best combination with PHP) _ db_query ($ database, $ query );
If ($ result)
While ($ r = MySQL (the best combination with PHP) _ fetch_array ($ result ))
{
Echo"
"While ($ r = MySQL (the best combination with PHP) _ fetch_array ($ result )){Echo"
$ R [0] | "$ Column = $ column + 1;}Echo"
"MySQL (the best combination with PHP) _ free_result ($ result );
"For ($ col = 0; $ col <$ column; $ col ++) echo"
$ R [$ col] | "Echo"
"}Echo"
"
}
Else echo "No data ."
MySQL (the best combination with PHP) _ free_result ($ result );
If ($ column! = 0) // ($ tablename = "software" | $ tablename = "techtalk ")
Echo"
- (As the mainstream development language) "> Home
- (As the mainstream development language )? Tablename = $ tablename "> Add a new entry
- (As the mainstream development language )? Tablename = $ tablename "> Edit an entry
- (As the mainstream development language )? Tablename = $ tablename "> Delete an entry
"
?>
To be continued.
Http://www.bkjia.com/PHPjc/508894.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/508894.htmlTechArticlephp (as the mainstream development language) 5 + MySQL (the best combination with PHP) 5 + apache (the most popular WEB server platform for Unix) 2 is already the most popular site creation mode. In...