Some corrections ;o)
$mysqli_type = array();
$mysqli_type[0] = "DECIMAL";
$mysqli_type[1] = "TINYINT";
$mysqli_type[2] = "SMALLINT";
$mysqli_type[3] = "INTEGER";
$mysqli_type[4] = "FLOAT";
$mysqli_type[5] = "DOUBLE";
$mysqli_type[7] = "TIMESTAMP";
$mysqli_type[8] = "BIGINT";
$mysqli_type[9] = "MEDIUMINT";
$mysqli_type[10] = "DATE";
$mysqli_type[11] = "TIME";
$mysqli_type[12] = "DATETIME";
$mysqli_type[13] = "YEAR";
$mysqli_type[14] = "DATE";
$mysqli_type[16] = "BIT";
$mysqli_type[246] = "DECIMAL";
$mysqli_type[247] = "ENUM";
$mysqli_type[248] = "SET";
$mysqli_type[249] = "TINYBLOB";
$mysqli_type[250] = "MEDIUMBLOB";
$mysqli_type[251] = "LONGBLOB";
$mysqli_type[252] = "BLOB";
$mysqli_type[253] = "VARCHAR";
$mysqli_type[254] = "CHAR";
$mysqli_type[255] = "GEOMETRY";
mysqli_fetch_field
result->fetch_field
(No version information available, might be only in CVS)
result->fetch_field — Retorna o próximo campo no conjunto de resultados
Descrição
Estilo de procedimento:
Estilo orientado a objeto (metodo):
A função mysqli_fetch_field() retorna a definição de uma coluna do conjunto de resultados como um objeto. Utilize esta função repetidamente para obter sobre todas as colunas no conjunto de resultados. mysqli_fetch_field() retorna FALSE quando não houverem mais campos.
Valores de retorno
Retorna um objeto o qual contém informações sobre a definição do campoou FALSE se não houver informação sobre campos disponÃvel.
| Propriedade | Descrição |
|---|---|
| name | O nome da coluna |
| orgname | Nome original da coluna se foi especificado um alias |
| table | O nome da tabela a qual este campo pertence (se não for calculada) |
| orgtable | Nome da tabela original se foi especificado um alias |
| def | O valor padrão para este campo, representando como uma string |
| max_length | O tamanho máximo do campo no conjunto de resultados. |
| flags | Um inteiro representando bit-flags para o campo. |
| type | O tipo de dados usado para este campo |
| decimals | O número de decimais usados (par campos integer) |
Veja também
mysqli_num_fields(), mysqli_fetch_field_direct(), mysqli_fetch_fields(), mysqli_field_seek().
Exemplo
Example#1 Estilo orientado a objeto
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT Name, SurfaceArea from Country ORDER BY Code LIMIT 5";
if ($result = $mysqli->query($query)) {
/* Get field information for all columns */
while ($finfo = $result->fetch_field()) {
printf("Name: %s\n", $finfo->name);
printf("Table: %s\n", $finfo->table);
printf("max. Len: %d\n", $finfo->max_length);
printf("Flags: %d\n", $finfo->flags);
printf("Type: %d\n\n", $finfo->type);
}
$result->close();
}
/* close connection */
$mysqli->close();
?>
Example#2 Estilo de procedimento
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT Name, SurfaceArea from Country ORDER BY Code LIMIT 5";
if ($result = mysqli_query($link, $query)) {
/* Get field information for all fields */
while ($finfo = mysqli_fetch_field($result)) {
printf("Name: %s\n", $finfo->name);
printf("Table: %s\n", $finfo->table);
printf("max. Len: %d\n", $finfo->max_length);
printf("Flags: %d\n", $finfo->flags);
printf("Type: %d\n\n", $finfo->type);
}
mysqli_free_result($result);
}
/* close connection */
mysqli_close($link);
?>
Os exemplos acima devem produzir a seguinte saÃda:
Name: Name Table: Country max. Len: 11 Flags: 1 Type: 254 Name: SurfaceArea Table: Country max. Len: 10 Flags: 32769 Type: 4
mysqli_fetch_field
06-Mar-2007 08:43
18-Jul-2006 02:26
There are MYSQLI_TYPE_* constants for the type property (listed in http://php.net/manual/en/ref.mysqli.php).
e.g.
<?php
if ($finfo->type == MYSQLI_TYPE_VAR_STRING)
// a VARCHAR
16-Aug-2005 01:15
<?
$fieldinfo = $result->fetch_field();
if ($fieldinfo & MYSQLI_NOT_NULL_FLAG) {
print "not null flag is set";
} else {
print "not null flag is NOT set";
}
?>
07-Jul-2005 07:56
The "type" property will return a numerical representation of a field type instead of a "meaningful" string.
Here is an array that may help you:
<?php
$mysqli_type = array();
$mysqli_type[0] = "decimal";
$mysqli_type[1] = "tinyint";
$mysqli_type[2] = "smallint";
$mysqli_type[3] = "int";
$mysqli_type[4] = "float";
$mysqli_type[5] = "double";
$mysqli_type[7] = "timestamp";
$mysqli_type[8] = "bigint";
$mysqli_type[9] = "mediumint";
$mysqli_type[10] = "date";
$mysqli_type[11] = "time";
$mysqli_type[12] = "datetime";
$mysqli_type[13] = "year";
$mysqli_type[252] = "blob"; // text, blob, tinyblob,mediumblob, etc...
$mysqli_type[253] = "string"; // varchar and char
$mysqli_type[254] = "enum";
?>

mysqli_fetch_field_direct