mysql_list_tables
(PHP 4, PHP 5, PECL mysql:1.0)
mysql_list_tables — List tables in a MySQL database
說明
Retrieves a list of table names from a MySQL database.
This function is deprecated. It is preferable to use mysql_query() to issue a SQL SHOW TABLES [FROM db_name] [LIKE 'pattern'] statement instead.
參數
- database
-
The name of the database
- link_identifier
-
MySQL 的連接識別符。如果沒有指定,預設使用最後被 mysql_connect() 打開的連接。如果沒有找到該連接,函式會嘗試呼叫 mysql_connect() 建立連接並使用它。如果發生意外,沒有找到連接或無法建立連接,系統發出 E_WARNING 級別的警告信息。
Return值
A result pointer resource on success, or FALSE on failure.
Use the mysql_tablename() function to traverse this result pointer, or any function for result tables, such as mysql_fetch_array().
更新日誌
版本 | 說明 |
---|---|
4.3.7 | This function became deprecated. |
範例
Example#1 mysql_list_tables() alternative example
<?php
$dbname = 'mysql_dbname';
if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
echo 'Could not connect to mysql';
exit;
}
$sql = "SHOW TABLES FROM $dbname";
$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);
?>
註釋
Note: 為了保證向下相容性,可以使用下面的別名,但不贊成使用它: mysql_listtables()