mysql_list_tables

(PHP 3, PHP 4, PHP 5)

mysql_list_tables -- 列出 MySQL 資料庫中的表

說明

resource mysql_list_tables ( string database [, resource link_identifier] )

mysql_list_tables() 接受一個資料庫名並返回和 mysql_query() 函數很相似的一個結果指標。用 mysql_tablename() 函數來遍歷此結果指標,或是任何使用結果表的函數,例如 mysql_fetch_array()

database 參數是需要被取得其中的的表名的資料庫名。若果失敗 mysql_list_tables() 返回 FALSE

為向下相容仍然可以使用本函數的別名 mysql_listtables(),但反對這樣做。

注: 該函數已經被移除了,請不要再使用該函數。您可以用指令 SHOW TABLES FROM DATABASE 來實現該函數的功能。

例子 1. mysql_list_tables() 例子

<?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);
?>

參見 mysql_list_dbs()mysql_tablename()