文字

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()

用户评论:

[#1] Haseldow [2004-04-23 05:00:10]

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";

[#2] pl at thinkmetrics dot com [2003-12-17 08:00:13]

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;
}

上一篇: 下一篇: