downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

mysql_thread_id> <mysql_stat
[edit] Last updated: Tue, 18 Jun 2013

view this page in

mysql_tablename

(PHP 4, PHP 5)

mysql_tablename取得表名

说明

string mysql_tablename ( resource $result , int $i )

mysql_tablename() 接受 mysql_list_tables() 返回的结果指针以及一个整数索引作为参数并返回表名。可以用 mysql_num_rows() 函数来判断结果指针中的表的数目。用 mysql_tablename() 函数来遍历此结果指针,或者任何处理结果表的函数,例如 mysql_fetch_array()

Example #1 mysql_tablename() 例子

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

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

    
mysql_free_result($result);
?>

参见 mysql_list_tables()



add a note add a note User Contributed Notes mysql_tablename - [2 notes]
up
1
Haseldow
9 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
-2
pl at thinkmetrics dot com
9 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;
}

 
show source | credits | sitemap | contact | advertising | mirror sites