mysql_tablename

(PHP 4, PHP 5)

mysql_tablenameAlanın tablo adını al

Uyarı

Bu eklentinin kullanımı PHP 5.5.0 itibariyle önerilmemekte olup PHP 7.0.0'da kaldırılmıştır. Bu eklentinin yerine ya mysqli ya da PDO_MySQL eklentisi kullanılmalıdır. MySQL API seçerken MySQL API'ye Bakış belgesi yardımcı olabilir. Bu işlevin yerine kullanılabilecekler:

  • SQL Sorgusu: SHOW TABLES

Açıklama

mysql_tablename(resource $sonuç, int $i): string|false

Bir sonuç'tan tablo adını alır.

Bu işlevin kullanımı önerilmemektedir. Bunun yerine, SHOW TABLES [FROM db_adı] [LIKE 'şablon'] şeklinde bir SQL ifadesi çalıştırmak için mysql_query() kullanılması tercih edilebilir.

Bağımsız Değişkenler

sonuç

mysql_list_tables() işlevinden döndürülen resource türünde bir sonuç göstericisi.

i

Tamsayı indisi (satır/tablo numarası)

Dönen Değerler

Başarı durumunda tablo adı, hata durumunda false döndürülür.

Bu sonuç göstericisini veya mysql_fetch_array() gibi sonuç tabloları üreten bir işlevden elde edilen işlevselliğin tersini elde etmek için mysql_tablename() işlevini kullanın.

Örnekler

Örnek 1 - mysql_tablename() örneği

<?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
"Tablo: ", mysql_tablename($result, $i), "\n";
}

mysql_free_result($result);
?>

Notlar

Bilginize:

mysql_num_rows() işlevi sonuç göstericisindeki tablo sayısını belirlemek için kullanılabilir.

Ayrıca Bakınız

add a note

User Contributed Notes 2 notes

up
5
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
-23
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