views:

146

answers:

3

Hi folks,

I need some help tracking down a bit of nitty gritty information on the information in the fetch_field method of a mysqli result object.

Specifically the type property - from the documentation it would seem that this field returns an integer...

Great!

I just can't seem to find a table that will let me translate the number to it's respective data type. I'm not even sure if I'm looking for php or mysql specific information. Push come to shove I can map it out myself, but I'd much rather if someone can point me to the actual documentation.

What am I missing?

A: 

I think that'll only give you some flags; nullable or not etc.

You might be better off querying INFORMATION_SCHEMA.COLUMNS to get that sort of details.

Kris
`flags` is a separate property. There is also a `type` property that does what he wants.
Ben James
It looks like both sets of constants (and probably others) are on this page.
Crazy Joe Malloy
+3  A: 

You can compare this number to various predefined constants, which are listed here:

http://www.php.net/manual/en/mysqli.constants.php

e.g. MYSQLI_TYPE_SHORT

Ben James
Beauty - thank-you sir!
Crazy Joe Malloy
+1  A: 

The PHP function mysqli_fetch_field() seems to map directly to the MySQL C API function mysql_fetch_field(), which returns a C struct of type MYSQL_FIELD, defined in mysql.h.

The type field of the structure is an enum_field_types, which is defined as follows:

enum_field_types {
   MYSQL_TYPE_DECIMAL,
   MYSQL_TYPE_TINY,
   MYSQL_TYPE_SHORT,
   MYSQL_TYPE_LONG,
   MYSQL_TYPE_FLOAT,
   MYSQL_TYPE_DOUBLE,
   MYSQL_TYPE_NULL,
   MYSQL_TYPE_TIMESTAMP,
   MYSQL_TYPE_LONGLONG,
   MYSQL_TYPE_INT24,
   MYSQL_TYPE_DATE, 
   MYSQL_TYPE_TIME,
   MYSQL_TYPE_DATETIME, 
   MYSQL_TYPE_YEAR,
   MYSQL_TYPE_NEWDATE, 
   MYSQL_TYPE_VARCHAR,
   MYSQL_TYPE_BIT,
   MYSQL_TYPE_NEWDECIMAL=246,
   MYSQL_TYPE_ENUM=247,
   MYSQL_TYPE_SET=248,
   MYSQL_TYPE_TINY_BLOB=249,
   MYSQL_TYPE_MEDIUM_BLOB=250,
   MYSQL_TYPE_LONG_BLOB=251,
   MYSQL_TYPE_BLOB=252,
   MYSQL_TYPE_VAR_STRING=253,
   MYSQL_TYPE_STRING=254,
   MYSQL_TYPE_GEOMETRY=255
};
Bill Karwin