This function return List of tables in a MySQL database.

Syntax: mysql_list_tables (database, connection)

Description:

The first argument “database” is Required.It specifies the name of the database.

The second argument “connection” is Optional.It specifies the MySQL connection. If not specified, the last connection opened by mysql_connect() or mysql_pconnect() is used.

This function deprecated. It is preferable to use mysql_query() to issue TABLES [FROM db_name] [LIKE ‘pattern’] statement instead.

Example:
Code:

$database_name = 'company';

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

$sql = "SHOW TABLES FROM $database_name";
$result = mysql_query($sql);

if (!$result) {
    echo "DB Error, could not list tables\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}

while ($row = mysql_fetch_row($result))  {
    echo "Table: {$row[0]}\n";
}

mysql_free_result($result);

Output:

Table: companydata

eXTReMe Tracker