【发布时间】:2015-04-25 21:23:14
【问题描述】:
我有三台服务器作为我的开发、暂存和生产服务器运行。运行的PHP版本分别为:5.5.23、5.5.9、5.5.20。
它们运行完全相同的代码。但是我的开发服务器抛出异常,而其他两个工作正常。例外情况如下:
错误:[PDOException] SQLSTATE[HY000]:一般错误:1366 不正确的整数值:第 1 行的列 'comment_id' 的''
请求网址:/cmets/add.json 堆栈跟踪: 0 /Users/me/Sites/MySite/lib/Cake/Model/Datasource/DboSource.php(460): PDOStatement->execute(Array)1
1 /Users/me/Sites/MySite/lib/Cake/Model/Datasource/DboSource.php(426): DboSource->_execute('INSERT INTO `po...', Array)1
2 /Users/me/Sites/MySite/lib/Cake/Model/Datasource/DboSource.php(1008): DboSource->execute('INSERT INTO `po...')1
3 /Users/me/Sites/MySite/lib/Cake/Model/Model.php(1744): DboSource->create(Object(Notification), Array, Array)1
4 /Users/me/Sites/MySite/app/Controller/CommentsController.php(181): 模型->保存(数组)1
5【内部函数】:CommentsController->add()
插入的值是bool(false),而数据库需要整数。所以我不得不为我的开发服务器处理这个问题:
//The comment id is set to false. Needs to turn it to NULL as DB can't handle false for integer
if($this->Comment->id === false)
$notification['Notification']['comment_id'] = NULL;
else
$notification['Notification']['comment_id'] = $this->Comment->id;
我的问题是:为什么我的登台和生产服务器可以处理这个问题(可能会自动将 false 值转换为整数),但我的开发服务器却不能?
如您所见,我的服务器正在运行CakePHP。我一直在查看 PDO 版本,但它似乎并没有给我太多的洞察力。我的开发服务器在我的 Mac Book Mac OS X 10.10 上运行。暂存和生产运行的是 Ubuntu 12.04。
【问题讨论】:
-
你用的是什么数据库?
-
@MartinKonecny MySQL