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

search for in the

mysql_thread_id> <mysql_stat
[edit] Last updated: Fri, 10 Feb 2012

view this page in

mysql_tablename

(PHP 4, PHP 5)

mysql_tablenameフィールドのテーブル名を得る

説明

string mysql_tablename ( resource $result , int $i )

result からテーブル名を取得します。

この関数は非推奨です。かわりに mysql_query() を利用して SHOW TABLES [FROM db_name] [LIKE 'pattern'] 文を発行することを推奨します。

パラメータ

result

mysql_list_tables() から返される 結果ポインタ resource

i

整数のインデックス(行/テーブル 番号)。

返り値

成功した場合にテーブル名、失敗した場合に FALSE を返します。

結果ポインタの中身を調べるために mysql_tablename() 関数を利用し、取得したテーブルを 利用するには mysql_fetch_array() などの関数を 利用してください。

例1 mysql_tablename() の例

<?php
mysql_connect
("localhost""mysql_user""mysql_password");
$result mysql_list_tables("mydb");
$num_rows mysql_num_rows($result);
for (
$i 0$i $num_rows$i++) {
    echo 
"Table: "mysql_tablename($result$i), "\n";
}

mysql_free_result($result);
?>

注意

注意:

結果ポインタに含まれるテーブル数を調べるには mysql_num_rows() 関数を利用します。

参考

  • mysql_list_tables() - MySQL データベース上のテーブルのリストを得る
  • mysql_field_table() - 指定したフィールドが含まれるテーブルの名前を取得する
  • mysql_db_name() - mysql_list_dbs のコール結果からデータベース名を取得する



add a note add a note User Contributed Notes mysql_tablename
Haseldow 23-Apr-2004 05:00
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";
pl at thinkmetrics dot com 17-Dec-2003 08:00
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 | stats | sitemap | contact | advertising | mirror sites