PHP MySQL get all table names for the specified database _php tutorial

Source: Internet
Author: User
Tags mysql tutorial php mysql
PHP tutorial MySQL tutorial get the specified database tutorial all table names
If you want to show MySQL a table name for a specified database, the method is simple, MySQL provides a show tables command, it returns a data, the following is a detailed example of what I do, tested fully available
*/

$CN = mysql_connect (' localhost ', ' root ', ' root ');
mysql_select_db (' Test ', $CN);
Print_r (Get_tables ());

/* Output Results

Array
(
[0] = ABC
[1] = Cn_user
[2] = Test1
)
*/

function get_tables ()//Get all table table names
{
$tables =array ();
$r =fetch_all ("Show Tables");
foreach ($r as $v)
{
foreach ($v as $v _)
{
$tables []= $v _;
}
}
return $tables;
}

function Fetch_all ($sql)
{
$rs =mysql_query ($sql);
$result =array ();
while ($rows =mysql_fetch_array ($rs, MYSQL_ASSOC))
{
$result []= $rows;
}

return $result;

}


This site original tutorial reprint note from http://www.bKjia.c0m reserved connection address, otherwise must investigate!
?>

http://www.bkjia.com/PHPjc/630783.html www.bkjia.com true http://www.bkjia.com/PHPjc/630783.html techarticle PHP Tutorial MySQL tutorial get the specified database tutorial all table names if you want to show MySQL a table name for a specified database, the method is simple, MySQL provides a show tables command, it returns ...

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