thinkphp returns database data all as strings
星星蓝蓝
星星蓝蓝 2019-04-08 16:59:40
0
5
1404

I use mamp for local development. There is no problem with the data taken out from the database. The database is defined as a numerical type and the returned value is also a numerical type.

For example: id: 35

But when I deployed it to the server, using centos nginx php, I found that all the data returned by the database were strings.

For example: id: "35"


Excuse me, do you need to configure it somewhere on the server? Thank you~

星星蓝蓝
星星蓝蓝

reply all(1)
Peter-Zhu

If you use a framework, such as thinkphp, there is an attribute $type in the model configuration, you can customize the returned data type, corresponding to setFetchMode() in PDO

  • reply I use thinkphp, can you be more specific? Thank you.
    星星蓝蓝 author 2019-04-08 17:49:14
  • reply That means I have to manually write the corresponding type for each model, right?
    星星蓝蓝 author 2019-04-08 17:50:13
  • reply Tried it and it works. Thanks. The automatic conversion equivalent to the driver cannot be used. Each model must be explicitly specified.
    星星蓝蓝 author 2019-04-08 18:00:27
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template