note 71178 rejected from function.is-int by tularis
| From: | tularis@php.net | Date: | Wed, 15 Nov 2006 09:06:50 +0000 |
| Subject: | note 71178 rejected from function.is-int by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-119745@lists.php.net to get a copy of this message | ||
Note Submitter: Cesar
----
Hi, I have been using PHP + MySQL for several years, but surprisingly enough I hadn't noticed
that mysql_fetch_array or mysql_fetch_object do return results without preserving the "main
type" of the database tables. Always, a string type is returned.
I mean, I would expect that if I have defined a field as "INT (11)", the query will return
a result as PHP-int (is_int($row->field) == 1), instead of a PHP-string. If the field value is of
type "tynyint", I would expect still a PHP-int, if a TEXT or VARCHAR I would expect a
PHP-string type, and so on...
Is there a way to avoid MySQL always sending back results as PHP-string type? Right now, I have
implemented a function which extracts the properties of the table field and force (casts) the type,
which is not quite an elegant procedure.