【发布时间】:2019-04-17 13:41:02
【问题描述】:
生产服务器是:
- Windows 10 专业版
- IIS 10.0.17134.1
- PHP 版本 7.1.17
我的本地机器:
- macOS,莫哈韦 10.14
- Apache/2.4.37 (Unix)
- PHP 版本 7.2.12
在两台机器上,我都使用相同的 laravel 5.4 应用程序,该应用程序在同一 Microsoft SQL 服务器上使用相同的源(数据库),并使用遵循此 link 安装的 sqlsrv PDO。
在reports表中,is_active字段是tinyint类型。
在windows机器上:
$report = App\Report::find(1);
return gettype($report->is_active); //returns string
在 macOS 机器上:
$report = App\Report::find(1);
return gettype($report->is_active); //returns integer
因此,当我在本地主机上进行开发并将更改推送到生产环境时,它在基本比较中失败了:
if($report->is_active === 1){
// works on localhost, but not on production
}
【问题讨论】:
-
只需在比较中去掉第三个等号。或者在返回时将值转换为 int。
if($report->is_active == 1){ -
查看
PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE或自己转换每个字符串。