User Contributed Notes 11 notes

Here's a bigger list of data types. I got this by creating every type I could and calling fetch_fields():

<?php$mysql_data_type_hash = array(1=>'tinyint',2=>'smallint',3=>'int',4=>'float',5=>'double',7=>'timestamp',8=>'bigint',9=>'mediumint',10=>'date',11=>'time',12=>'datetime',13=>'year',16=>'bit',//252 is currently mapped to all text and blob types (MySQL 5.0.51a)253=>'varchar',254=>'char',246=>'decimal');?>

Warning!This function is not only more memory consuming than expected but the consumption also depends on the size of the result set. So if you realy only want to get your field_names you might want to append " LIMIT 1" or use mysqli->unbuffered_query() to save yourself from a memory bloat.

Beware of the fact that the ->def property NEVER gets filled with the correct default field value, so it's totally USELESS.

This happens NOT for a bug in php (so don't go filling in a bug report), but happens BY DESIGN, since the MySQL C API call doesn't fill in this value, unless you call the mysql_list_fields() function, which Php doesn't.

Also, be aware that if you're using a query which contains subqueries, the primary key/autoincrement flags do NOT get passed along, even if the field you're looking at is the primary autoincrement key of the master table:

SELECT * from (SELECT id from areas) AS subareas

and you'll find primary key and autoinc flags off on id field, even if id was the primary autoinc key of areas table.

This also is by design, i think, since it's supposed that if we're using a subquery then the primary key/autoinc stuff might have no sense at all, since in the result set we can compose fileds from many different tables.

NOT_NULL_FLAG 1 /* Field can't be NULL */ PRI_KEY_FLAG 2 /* Field is part of a primary key */ UNIQUE_KEY_FLAG 4 /* Field is part of a unique key */ MULTIPLE_KEY_FLAG 8 /* Field is part of a key */ BLOB_FLAG 16 /* Field is a blob */ UNSIGNED_FLAG 32 /* Field is unsigned */ ZEROFILL_FLAG 64 /* Field is zerofill */ BINARY_FLAG 128 /* Field is binary */ ENUM_FLAG 256 /* field is an enum */ AUTO_INCREMENT_FLAG 512 /* field is a autoincrement field */ TIMESTAMP_FLAG 1024 /* Field is a timestamp */