MySQL integer field is returned as string in PHP

前端 未结 15 2171
南旧
南旧 2020-11-22 16:17

I have a table field in a MySQL database:

userid INT(11)

So I am calling it to my page with this query:

\"SELECT userid FR         


        
15条回答
  •  心在旅途
    2020-11-22 17:11

    In my project I usually use an external function that "filters" data retrieved with mysql_fetch_assoc.

    You can rename fields in your table so that is intuitive to understand which data type is stored.

    For example, you can add a special suffix to each numeric field: if userid is an INT(11) you can rename it userid_i or if it is an UNSIGNED INT(11) you can rename userid_u. At this point, you can write a simple PHP function that receive as input the associative array (retrieved with mysql_fetch_assoc), and apply casting to the "value" stored with those special "keys".

提交回复
热议问题