mysql_tablename

(PHP 4, PHP 5)

mysql_tablename필드가 존재하는 테이블명을 반환

설명

string mysql_tablename ( resource $result , int $i )

result로부터 테이블명을 반환한다.

이 함수는 사용이 권장되지 않는다. 대신, SHOW TABLES [FROM db_name] [LIKE 'pattern'] SQL을 mysql_query()로 실행하도록 권장한다.

인수

result

resource 결과 포인터는 mysql_list_tables()로부터 반환되는 것이다.

i

정수형 색인(행/테이블 번호)

반환값

성공하면 테이블명을, 실패하면 FALSE를 반환한다.

결과 포인터를 탐색하기 위해 mysql_tablename()를 사용하거나, mysql_fetch_array()와 같은 결과 테이블을 위한 특정 함수를 사용한다.

예제

Example #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);
?>

주의

Note:

mysql_num_rows()는 결과 포인터에서 테이블의 개수를 가져오기 위해 사용된다.

참고

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