MySQL integer field is returned as string in PHP

前端 未结 15 2361
南旧
南旧 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 16:51

    When you select data from a MySQL database using PHP the datatype will always be converted to a string. You can convert it back to an integer using the following code:

    $id = (int) $row['userid'];

    Or by using the function intval():

    $id = intval($row['userid']);

提交回复
热议问题