php mysql get all the table name of the specified database

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags array data display examples get mysql mysql tutorial mysql_connect

php mysql tutorial to get all the specified database table name If you want to display mysql a specified database table name is very simple, mysql provides a show tables command, it returns a data, let me look at the detailed examples, Tested is fully available
* /

$ cn = mysql_connect ('localhost', 'root', 'root');
mysql_select_db ('test', $ cn);
print_r (get_tables ());

/ * Output the result

array
(
[0] => abc
[1] => cn_user
[2] => test1
)
* /

function get_tables () / / Get all the table name
{
$ 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;

}

?>

Related Article

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.