Get the PHP program for all the table names in the MySQL database

Source: Internet
Author: User
Tags mysql tutorial php tutorial

In fact, we used only the MySQL tutorial show usage in fact one, in the MySQL simple operation as follows

Show Table

This will show all the tables, but in the PHP tutorial, we'll look at the following code

$server = ' localhost ';
$user = ' root ';
$pass = ';
$dbname = ' dayanmei_com ';
$conn = mysql_connect ($server, $user, $pass);
if (! $conn) Die ("Database tutorial system Connection failed!") ");
mysql_select_db ($dbname) or Die ("database connection failed!) ");
$result = mysql_query ("Show Tables");
while ($row = Mysql_fetch_array ($result))
{
echo $row [0]. "";
}
Mysql_free_result ($result);

Use the mysql_query query function to save the return table to a data so that you can iterate through it.

Other actions about show

show databases;
Show tables from db_name;

Show columns from table_name to db_name;
Show index from Talbe_name [from db_name];

Show status;
Show variables;

Show [Full] processlist;
Show table status [from db_name];

Show grants for user;


In addition to status,processlist and grants, the other can have the like wild option, which can use the SQL '% ' and ' _ ' characters;

Show databases like '%t ';

A database with the ' t ' character at the end of all database names will be listed


Of course, in these SQL, you can also use Db_name.table_name to replace table_name from db_name This will be easier to write!

If a user does not have any permissions on a table, the table is not displayed in the output in show tables or Mysqlshow db_name


You may remember describe TABLE_NAME, which achieved the same effect as show columns from Db_name.table_name

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.