欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

thinkphp不会识别unsigned int数据类型,会导致sql执行异常

更新时间: 2014-01-05 02:06:41 责任编辑: Author_N1

 

thinkphp不会识别unsigned int数据类型,会导致sql执行错误
数据库中是 unsigned int, 支持40多亿, 但用tp进行查询的时候, where方法会自动把大于2147483647的(有符号int最大值) 转化成 2147483647


print_r($condition);
$Mode->where($condition)->find();
echo $Mode->getlastSql();


结果:

Array
(
[sid] => 2147645095
[type] => icili
)
SELECT * FROM `al_qitadianying` WHERE ( `sid` = 2147483647 ) AND ( `type` = 'icili' ) LIMIT 1


sid 字段是 unsigned in

---------------------------------------------
下面是我自己的测试结果

我测试了,
$data['userID'] = "davidhuang";
$data['sysID'] = 2147645095;
$data['loginTime'] = datetime();
$data['loginStatus'] = 0;
$data['validStatus'] = 0;
$result = M("loginLog")->add($data);
dump(M()->getLastSql());
生成的sql是
INSERT INTO `login_log` (`userID`,`sysID`,`loginTime`,`loginStatus`,`validStatus`) VALUES ('davidhuang',-2147322201,'2013-11-19 09:58:44',0,0)
sysID的类型是
int(11) UNSIGNED
应该是个bug。

测试TP版本 3.1.3

看下tp的源码:
/**
* 数据类型检测
* access protected
* @param mixed $data 数据
* @param string $key 字段名
* return void
*/
protected function _parseType(&$data,$key) {
$fieldType = strtolower($this->fields['_type'][$key]);
if(false !== strpos($fieldType,'int')) {
$data[$key] = intval($data[$key]);
}elseif(false !== strpos($fieldType,'float') || false !== strpos($fieldType,'double')){
$data[$key] = floatval($data[$key]);
}elseif(false !== strpos($fieldType,'bool')){
$data[$key] = (bool)$data[$key];
}
}
它用的是intval,转换后的最大值是2147483647。
API说明:
intval($var, $base)
Get the integer value of a variable
link http://www.php.net/manual/en/function.intval.php
@param var mixed
The scalar value being converted to an integer
@param base int[optional]
The base for the conversion
return int The integer value of var on success, or 0 on failure. Empty arrays and objects return 0, non-empty arrays and objects return 1.
The maximum value depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. So for example on such a system, intval('1000000000000') will return 2147483647. The maximum signed integer value for 64 bit systems is 9223372036854775807.
Strings will most likely return 0 although this depends on the leftmost characters of the string. The common rules of integer casting apply.
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:06:41
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/5733/
本文WWW.DOC100.NET DOC100.NET版权所有。