search

Home  >  Q&A  >  body text

thinkphp returns database data all as strings

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~

星星蓝蓝星星蓝蓝2055 days ago1395

reply all(5)I'll reply

  • 天蓬老师

    天蓬老师2019-04-08 17:35:42

    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
    0
  • 星星蓝蓝

    I use thinkphp, can you be more specific? Thank you.

    星星蓝蓝 · 2019-04-08 17:49:14
    星星蓝蓝

    That means I have to manually write the corresponding type for each model, right?

    星星蓝蓝 · 2019-04-08 17:50:13
    星星蓝蓝

    Tried it and it works. Thanks. The automatic conversion equivalent to the driver cannot be used. Each model must be explicitly specified.

    星星蓝蓝 · 2019-04-08 18:00:27
  • Cancelreply