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] = "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_direct
result->fetch_field_direct
(No version information available, might be only in CVS)
result->fetch_field_direct — Obtem meta dados para um único campo
Descrição
Estilo de procedimento:
mixed mysqli_fetch_field_direct
( object $result
, int $fieldnr
)
Estilo orientado a objeto (metodo):
result
mixed
fetch_field_direct
( int $fieldnr
)
mysqli_fetch_field_direct() retorna um objeto o qual contém informações da definição de um campo do conjunto de resultados especificado. O valor de fieldnr deve estar no intervalo entre 0 e número de campos - 1.
Valores de retorno
Retorna um objeto o qual contém informações das definições de um campo ou FALSE se não houver informações sobre o campo especificado com fieldnr disponíveis.
| Atibuto | 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, representado por uma string |
| max_length | O limite de tamanho para o campo no conjunto de resultados. |
| flags | Um inteiro representando bit-flags para o campo. |
| type | O tipo de dados para este campo |
| decimals | O número de casas decimais usadas (para campos integer) |
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 Name LIMIT 5";
if ($result = $mysqli->query($query)) {
/* Get field information for column 'SurfaceArea' */
$finfo = $result->fetch_field_direct(1);
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", $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 Name LIMIT 5";
if ($result = mysqli_query($link, $query)) {
/* Get field information for column 'SurfaceArea' */
$finfo = mysqli_fetch_field_direct($result, 1);
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", $finfo->type);
mysqli_free_result($result);
}
/* close connection */
mysqli_close($link);
?>
Os exemplos acima devem produzir a seguinte saída:
Name: SurfaceArea Table: Country max. Len: 10 Flags: 32769 Type: 4
User Contributed Notes
mysqli_fetch_field_direct
mysqli_fetch_field_direct
Jonathan
06-Mar-2007 08:46
06-Mar-2007 08:46

mysqli_fetch_assoc