You can do this with...
...depending on the extension you want to use. The first is not recommended because the mysql extension is deprecated. The third is still experimental.
The comments at these hyperlinks do a good job of explaining how to set your type from a plain old string to its original type in the database.
Some frameworks also abstract this (CodeIgniter provides $this->db->field_data()
).
You could also do guesswork--like looping through your resulting rows and using is_numeric() on each. Something like:
foreach($result as &$row){
foreach($row as &$value){
if(is_numeric($value)){
$value = (int) $value;
}
}
}
This would turn anything that looks like a number into one...definitely not perfect.