(PHP 4, PHP 5)
mysql_list_tables — List tables in a MySQL database
Esta função tornou-se defasada a partir do PHP 4.3.0 e ela e a extensão MySQL original foram removidas a partir do PHP 7.0.0. Em vez disso, use as extensões MySQLi ou PDO_MySQL, que são desenvolvidas ativamente. Veja também o guia MySQL: escolhendo uma API. Alternativas a esta função incluem:
SHOW TABLES FROM dbname
Retrieves a list of table names from a MySQL database.
This function is deprecated. It is preferable to use mysql_query() to issue an SQL SHOW TABLES [FROM db_name] [LIKE 'pattern']
statement instead.
database
The name of the database
link_identifier
A conexão MySQL. Se o identificador da conexão não for especificado, a última conexão aberta por mysql_connect() será usada. Se não houver uma conexão anterior, haverá uma tentativa de criar uma como se mysql_connect() tivesse sido chamada sem argumentos. Se nenhuma conexão for encontrada ou estabelecida, um erro de nível E_WARNING
será gerado.
A result pointer resource on success ou false
em caso de falha.
Use the mysql_tablename() function to traverse this result pointer, or any function for result tables, such as mysql_fetch_array().
Versão | Descrição |
---|---|
4.3.7 | This function became deprecated. |
Exemplo #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);
?>
Nota:
Para compatibilidade com versões anteriores, o seguinte apelido defasado pode ser usado: mysql_listtables()