Yii2-ActiveRecord-类型转换 [英] Yii2 - ActiveRecord - type casting
本文介绍了Yii2-ActiveRecord-类型转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在yii2 activerecord中不支持mysql的float,double,decimal数据类型! (或者我错了) 当我访问此列(float,double,decimal)时,yii2返回字符串.
in yii2 activerecord float,double,decimal datatype of mysql not support ! (Or I'm wrong) when i access to this column(float,double,decimal) , yii2 return string.
我如何将mysql的float,double,decimal数据类型转换为php float?
how i can type casting float,double,decimal datatype of mysql to php float ?
mytable(id int, f1 float, f2 double, f3 decimal(10,2))
例如在activerecord类中:
for example in activerecord class :
public function filters(){
// return [['f1','f2','f3'] => 'float', ...];
}
推荐答案
Yii返回无符号整数和浮点数的字符串.这是因为通常DBMS类型可以代表PHP以上的类型,并且我们希望保持精度.
Yii returns string for unsigned integers and floating numbers. That's because typically DBMS type can represent more than PHP and we want to preserve precision.
这篇关于Yii2-ActiveRecord-类型转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文