PHP5 Management code example for arbitrary database tables for MYSQL5 (i) _php tutorial

Source: Internet
Author: User
PHP (as the current mainstream development language) 5+mysql (and PHP collocation of the best combination) 5+apache (Unix platform of the most popular Web server platform) 2 is now the most popular site to build the model. In the case of MySQL (the best combination with PHP), it would be a bit cumbersome to use only the SQL language to operate on MySQL (the best combination of PHP collocation). So I refer to the code on the Internet through the modification of writing a set of various tables to add, delete, modify the record of PHP (as the current mainstream development language) code. For everyone to refer to entertainment.

The following posted code in PHP (as the current mainstream development language) 5+mysql (and PHP collocation of the best combination) 5+apache (Unix platform most popular Web server platform) 2 for WinXP debugging through.

First explain the scope of the code, according to the characteristics of most tables, each table has an ID, so the code applies to the first column ID of the table. As for the name of what does not matter, it is important that the code is the default according to the first column prima (the most complete virtual host management System) RY key to operate. There are no restrictions, this code can operate on any column of the table. Disadvantage: No input review is performed. So do not empty lines when entering records and do not lose mismatched types, which need to be matched with the build table of MySQL (and the best combination of PHP collocation).

NOTE: Reminders! The above code in copy must pay attention to the editor in the front of each line of code to remove, or PHP (as the current mainstream development language) 5 compiled.
And in each file $database is currently sunsite, $table for software, this can be modified as needed.

The first is index.php (as the current mainstream development language), the main implementation function for the user to enter the table name, and then click the View button to see the contents of the table. is also the default home page.

index.php (as the current mainstream development language)



Admin

Please input the table name





Then there is tables.php (which is now the mainstream development language), which functions to show the contents of the table. and add the deletion and modification of the entrance.
Tables.php (as the current mainstream development language)


Current table


$database = "SunSITE"
$tablename = $_request[tablename];
echo "

Data from $tablename

"
MySQL (and PHP collocation best combination) _connect ("localhost", "root", "") or Die ("problem connecting to DataBase");
$query = "Show columns from $tablename"
$result = MySQL (the best combination of PHP collocation) _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 of PHP collocation) _db_query ($database, $query);
if ($result)
while ($r = MySQL (best combination with PHP) _fetch_array ($result))
{
echo "





"while ($r = MySQL (best combination with PHP) _fetch_array ($result)) {echo" "$column = $column + 1;} echo " "MySQL (the best combination of PHP collocation) _free_result ($result); "For ($col =0; $col < $column; $col + +) echo" "Echo" "}echo"
$r [0]
$r [$col]
"
}
else echo "No data."
MySQL (the best combination of PHP collocation) _free_result ($result);
if ($column! = 0)//($tablename = = "Software" | | $tablename = = "TechTalk")
echo "



    • (as the current mainstream development language) ">home
    • (as the current mainstream development language)? tablename= $tablename ">add A new entry
    • (as the current mainstream development language)? tablename= $tablename ">edit an entry
    • (as the current mainstream development language)? tablename= $tablename ">delete an entry
"
?>

Cond.

http://www.bkjia.com/PHPjc/508894.html www.bkjia.com true http://www.bkjia.com/PHPjc/508894.html techarticle PHP (as the current mainstream development language) 5+mysql (and PHP collocation of the best combination) 5+apache (Unix platform of the most popular Web server platform) 2 is now the most popular site to build the model. In the right of ...

  • 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.