When utilizing mysql_fetch_assoc in PHP, how do i allow it to be return the right data types? At this time it seems to transform everything to strings, I'd prefer whether it left the Ints as Ints, and in some way designated the Date/Time as either Object or in some way diverse from strings.

The reason behind this really is that i'm using PHP like a after sales to some Flex application, and Flex has some features for example instantly discovering return types, which aren't effective that well if everything is available in like a string.

I believe a great strategy here's to programatically determine the datatype of every column inside a table, and cast the came back results accordingly. This will help you to communicate with your database inside a more consistent and straightforward manner while still providing you with the control you must have your variables storing the right datatype.

One possible solution: You could utilize mysql_fetch_field() to obtain an item that holds meta-data concerning the table column after which cast your string to the preferred type.

//run query and get field information about the row in the table
$meta = mysql_fetch_field($result, $i);

//get the field tipe of the current column
$fieldType = $meta->type

A complete example are available here: http://us2.php.net/manual/en/function.mysql-fetch-field.php

Since PHP is loosely typed, you ought to have a comparatively easy time with this particular.

If you work with OO techniques, you can produce a class with this particular functionality within the setter() techniques so it's not necessary to have duplicate code.

You can develop a mysql-specific layer around mdb2 that instantly picks up area types while using SHOW COLUMNS command, but that will type of defeat the objective of using mdb2.

Bear in mind, also, that mysql suports integers well outdoors of PHP's range, (UNSIGNED BIGINT is 64 bits PHP supports, at best, 64 bit signed ints, and fewer on 32 bit platforms) so instantly casting might be undesirable in certain contexts. In individuals cases, you want to help keep the big ints within their string form, and manipulate all of them with bcmath