PDO MSSQL - 返回了错误的 BIGINT 值
PDO MSSQL - wrong BIGINT value returned
我正在尝试查询 MSSQL 数据库上的 BIGINT 主键,一些 returned 值变成四舍五入,与数据库中存储的值不同:
9200000000000359 存在于数据库中,以及 9200000000000361。查询这两个值中的任何一个都将 return 9200000000000360(旁注:数据库中不存在此值)。
这些值似乎首先(错误地)转换为二进制,当转换回来时,它们产生的值与原始值不同。但是我在 64 位机器上使用 PHP 5.6,而不是 32 位。同时使用 dblib 和 odbc 驱动程序时也会发生这种情况。
我可以在 SQLServer 上或 php.ini 配置中进行任何设置以获得正确的值吗?
如果您在 Windows 下使用 PHP,那么您应该升级到 PHP 7+。
64-bit platforms usually have a maximum value of about 9E18, except on
Windows prior to PHP 7, where it was always 32 bit.
x86_64 Builds
The x64 builds of PHP 5 for Windows are experimental, and do not provide 64-bit integer or large file support.
PHP 7 provides full 64-bit support. The x64 builds of PHP 7 support native 64-bit integers, LFS, memory_limit and much more.
Yii 似乎将结果转换为浮点数。即使是普通的 PHP 7 在 64 位机器上 returns 以下输出:
php > echo (int)(float)9200000000000359;
9200000000000360
使用普通PHP和PDO,返回正确的输出:
$db = new PDO($dbc->connectionString, $dbc->username, $dbc->password);
$stmt = $db->query("...... WHERE id = 9200000000000359");
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)[0]['id']);
// output:
array(1) {
[0] => string(16) "9200000000000359"
}
我正在尝试查询 MSSQL 数据库上的 BIGINT 主键,一些 returned 值变成四舍五入,与数据库中存储的值不同:
9200000000000359 存在于数据库中,以及 9200000000000361。查询这两个值中的任何一个都将 return 9200000000000360(旁注:数据库中不存在此值)。
这些值似乎首先(错误地)转换为二进制,当转换回来时,它们产生的值与原始值不同。但是我在 64 位机器上使用 PHP 5.6,而不是 32 位。同时使用 dblib 和 odbc 驱动程序时也会发生这种情况。
我可以在 SQLServer 上或 php.ini 配置中进行任何设置以获得正确的值吗?
如果您在 Windows 下使用 PHP,那么您应该升级到 PHP 7+。
64-bit platforms usually have a maximum value of about 9E18, except on Windows prior to PHP 7, where it was always 32 bit.
x86_64 Builds The x64 builds of PHP 5 for Windows are experimental, and do not provide 64-bit integer or large file support.
PHP 7 provides full 64-bit support. The x64 builds of PHP 7 support native 64-bit integers, LFS, memory_limit and much more.
Yii 似乎将结果转换为浮点数。即使是普通的 PHP 7 在 64 位机器上 returns 以下输出:
php > echo (int)(float)9200000000000359;
9200000000000360
使用普通PHP和PDO,返回正确的输出:
$db = new PDO($dbc->connectionString, $dbc->username, $dbc->password);
$stmt = $db->query("...... WHERE id = 9200000000000359");
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)[0]['id']);
// output:
array(1) {
[0] => string(16) "9200000000000359"
}