phpday 2027 - Call for Papers

mysql_list_fields

(PHP 4, PHP 5)

mysql_list_fields — List MySQL table fields

Avviso

Questa funzione è stata deprecata in PHP 5.4.0, ed essa e l'intera estensione MySQL originale sono state rimosse in PHP 7.0.0. Al suo posto, usare l'estensione MySQLi o PDO_MySQL, entrambe attivamente sviluppate. Vedere anche la guida MySQL: scelta dell'API. Le alternative a questa funzione includono:

  • SQL Query: SHOW COLUMNS FROM sometable

Descrizione

function mysql_list_fields(string $database_name, string $table_name, resource $link_identifier = NULL): resource

Retrieves information about the given table name.

This function is deprecated. It is preferable to use mysql_query() to issue an SQL SHOW COLUMNS FROM table [LIKE 'name'] statement instead.

Elenco dei parametri

database_name

The name of the database that's being queried.

table_name

The name of the table that's being queried.

link_identifier

La connessione MySQL. Se l'identificativo di connessione non è specificato, viene usata l'ultima connessione aperta da mysql_connect(). Se tale connessione non viene trovata, si cercherà di crearne una come se mysql_connect() fosse stata chiamata senza argomenti. Se nessuna connessione viene trovata o stabilita, viene generato un errore di livello E_WARNING.

Valori restituiti

A result pointer resource on success, or false on failure.

The returned result can be used with mysql_field_flags(), mysql_field_len(), mysql_field_name() e mysql_field_type().

Esempi

Example #1 Alternate to deprecated mysql_list_fields()

<?php
$result = mysql_query("SHOW COLUMNS FROM sometable");
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}
if (mysql_num_rows($result) > 0) {
    while ($row = mysql_fetch_assoc($result)) {
        print_r($row);
    }
}
?>

Il precedente esempio visualizzerà qualcosa di simile a:

Array
(
    [Field] => id
    [Type] => int(7)
    [Null] =>
    [Key] => PRI
    [Default] =>
    [Extra] => auto_increment
)
Array
(
    [Field] => email
    [Type] => varchar(100)
    [Null] =>
    [Key] =>
    [Default] =>
    [Extra] =>
)

Note

Nota:

Per la compatibilità all'indietro, è possibile utilizzare il seguente sinonimo deprecato: mysql_listfields()

Vedere anche:

+add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top