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, 25 May 2012

view this page in

mysql_tablename

(PHP 4, PHP 5)

mysql_tablenameObtiene el nombre de la tabla de un campo

Descripción

string mysql_tablename ( resource $result , int $i )

Recupera el nombre de tabla desde result.

Esta función está obsoleta. Es preferible usar mysql_query() para emitir una consulta SQL SHOW TABLES [FROM db_name] [LIKE 'pattern'] en su lugar.

Parámetros

result

Un puntero de resultado resource que se devuelve desde mysql_list_tables().

i

El índice integer (número de fila/tabla)

Valores devueltos

El nombre de la tabla en caso de éxito o FALSE en caso de error.

Use la función mysql_tablename() para atravesar este puntero de resultado, o cualquier función para resultar tablas, tal como mysql_fetch_array().

Ejemplos

Ejemplo #1 Ejemplo de 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);
?>

Notas

Nota:

La función mysql_num_rows() puede ser usada para determinar el número de tablas en el puntero del resultado.

Ver también



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 | sitemap | contact | advertising | mirror sites