MySQL integer field is returned as string in PHP

前端 未结 15 2362
南旧
南旧 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:02

    No. Regardless of the data type defined in your tables, PHP's MySQL driver always serves row values as strings.

    You need to cast your ID to an int.

    $row = $result->fetch_assoc();
    $id = (int) $row['userid'];
    

提交回复
热议问题