PHP4 and MySQL database operation function detailed explanation (vi)

Source: Internet
Author: User
Tags connect mysql mysql in table name mysql database

(8) Take the database name and table name (2):

1, Mysql_list_dbs ()
Format: int Mysql_list_dbs (int link_identifier);
Gets all available database names (db name).

Example:

<?php
$connect = mysql_connect ($host, $USR, $pwd);
$dbs = Mysql_list_dbs ($connect);
$rows = mysql_num_rows ($dbs);
echo "Database total:". $rows;
$i = 0;
while ($i < $rows)
{
$db _name[$i] = Mysql_tablename ($dbs, $i);
echo $db _name[$i];
$i + +;
}
?>
You can display all of the database names in MySQL, in turn.
Note: Equivalent to the show databases command in MySQL

2, Mysql_list_tables ()
Format: int mysql_list_tables (string database name);
Displays the names of all tables under the database, table name.

Example:

<?php
$connect = mysql_connect ($host, $USR, $pwd);
$tables = Mysql_list_tables ("MySQL");
$rows = mysql_num_rows ($tables);
echo "Table total:". $rows;
$i = 0;
while ($i < $rows)
{
$table _name[$i] = Mysql_tablename ($tables, $i);
echo $table _name[$i];
$i + +;
}

?>

You can display the names of all the tables under MySQL in turn
Note: Equivalent to the show Tables command in MySQL (use MySQL command to select 1 databases first)






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.