mysql_tablename

(PHP 4, PHP 5)

mysql_tablenameZwraca nazwę tabeli

Opis

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

mysql_tablename() przyjmuje jako parametry wskaźnik wyniku zwrócony przez mysql_list_tables() oraz indeks, zwracając nazwę tabeli. Liczbę tabel zwróconych w wyniku można określić używając funkcji mysql_num_rows().

Przykład #1 Przykład użycia mysql_tablename()

<?php
mysql_connect
('localhost''uzytkownik''haslo');
$result mysql_list_tables('baza');

for (
$i 0$i mysql_num_rows($result); $i++)
    
printf ("Tabela: %s\n"mysql_tablename($result$i));

mysql_free_result($result);
?>

Patrz także: mysql_list_tables().

add a note add a note

User Contributed Notes 2 notes

up
3
Haseldow
19 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