firzen / QeePHP

QeePHP 2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

获取数据库的类型全部变成了string

gtspoon opened this issue · comments

commented

代码输出

$customer = Customer::find()->asArray()->getOne();
var_dump($customer);
array (size=8)
  'id' => string '1' (length=1)
  'phone_number' => string '180.......' (length=11)

非常奇怪,id字段的类型为init,但是这样子获取,id的类型却变成了string,有什么解决办法吗?

是什么数据库?

代码输出

$customer = Customer::find()->asArray()->getOne();
var_dump($customer);
array (size=8)
  'id' => string '1' (length=1)
  'phone_number' => string '180.......' (length=11)

非常奇怪,id字段的类型为init,但是这样子获取,id的类型却变成了string,有什么解决办法吗?

commented

是什么数据库?

代码输出

$customer = Customer::find()->asArray()->getOne();
var_dump($customer);
array (size=8)
  'id' => string '1' (length=1)
  'phone_number' => string '180.......' (length=11)

非常奇怪,id字段的类型为init,但是这样子获取,id的类型却变成了string,有什么解决办法吗?

mysql,使用的是mysqli,原来是设置问题
具体参考(https://www.php.net/manual/mysqli.options.php)

在library\db\adapter\mysqli.php的数据连接完成后,增加了一个mysqli的设置就可以了
$this->_conn->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true);

代码上下文:

$this->_conn=new mysqli();
$this->_conn->connect($host,$this->_dsn['login'],$this->_dsn['password']);
$this->_conn->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true);

这个问题其实不只是mysqli有,pgsql或者sqlsrv都会出现。建议改成 getOne()->toArray() 试一下