Developer Forums | About Us | Site Map
Search  
HOME > PHPMANUAL


Sponsors





Web Host
site hosted by netplex
Partners

Online Manuals

mysql_list_tables

(PHP 3, PHP 4 )

mysql_list_tables -- List tables in a MySQL database

Description

resource mysql_list_tables ( string database [, resource link_identifier])

mysql_list_tables() takes a database name and returns a result pointer much like the mysql_query() function. Use the mysql_tablename() function to traverse this result pointer, or any function for result tables, such as mysql_fetch_array().

The database parameter is the name of the database to retrieve the list of tables from. Upon failure, mysql_list_tables() returns FALSE.

For downward compatibility, the function alias named mysql_listtables() can be used. This is deprecated however and is not recommended.

Note: This function has been deprecated. Do not use this function. Use the command SHOW TABLES FROM DATABASE instead.

Example 1. mysql_list_tables() example

<?php
    $dbname = 'mysql_dbname';

    if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
        print 'Could not connect to mysql';
        exit;
    }

    $result = mysql_list_tables($dbname);
    
    if (!$result) {
        print "DB Error, could not list tables\n";
        print 'MySQL Error: ' . mysql_error();
        exit;
    }
    
    while ($row = mysql_fetch_row($result)) {
        print "Table: $row[0]\n";
    }

    mysql_free_result($result);
 ?>

See also mysql_list_dbs() and mysql_tablename().

Copyright 2004-2024 GrindingGears.com. All rights reserved. Site hosted by NETPLEX