mysql_tablename

(PHP 4, PHP 5)

mysql_tablenameRetorna o nome da tabela do campo

Descrição

mysql_tablename ( resource $result , int $i ) : string

mysql_tablename() usa um ponteiro de resultado retornado por mysql_list_tables() ou um índice inteiro e retorna o nome da tabela A função mysql_num_rows() pode ser usada para determinar o número de tabelas no ponteiro do resultado. Use a função mysql_tablename() para transpor o resultado, ou qualquer função para pegar o resultado como mysql_fetch_array().

Exemplo #1 Exemplo mysql_tablename()

<?php
mysql_connect
("localhost""mysql_user""mysql_password");
$result mysql_list_tables("mydb");

for (
$i 0$i mysql_num_rows($result); $i++) {
    echo 
"Table: "mysql_tablename($result$i), "\n";
}

mysql_free_result($result);
?>

Veja também mysql_list_tables().

add a note add a note

User Contributed Notes 2 notes

up
3
Haseldow
20 years ago
Another way to check if a table exists:

if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$table."'"))==1) echo "Table exists";
else echo "Table does not exist";
up
-15
pl at thinkmetrics dot com
20 years ago
A simple function to check for the existance of a table:

function TableExists($tablename, $db) {
   
    // Get a list of tables contained within the database.
    $result = mysql_list_tables($db);
    $rcount = mysql_num_rows($result);

    // Check each in list for a match.
    for ($i=0;$i<$rcount;$i++) {
        if (mysql_tablename($result, $i)==$tablename) return true;
    }
    return false;
}
To Top