MySql位列在PHP 7.1中返回怪异的大量数字(在以前的版本中不如此) [英] MySql bit columns returns weird large number in PHP 7.1 (not in previous versions)

查看:59
本文介绍了MySql位列在PHP 7.1中返回怪异的大量数字(在以前的版本中不如此)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试使用PHP 5.5开发的PHP网站,看它是否与PHP 7.1兼容,我发现了一个非常奇怪的问题.

I am testing my PHP site developed with PHP 5.5 to see if it is compatible with PHP 7.1 and I found a very strange problem.

问题在于,对带有BIT(1)列的表进行简单选择会返回18位数字,而不是返回以前PHP版本的0/1.

The problem is that doing a simple select on a table with a BIT(1) column returns an 18 digit number instead of a 0 / 1 that return previous PHP versions.

有问题的版本是PHP 7.1.9,我尝试正常运行的其他版本是5.5.12和7.0.23.所有测试均在WAMP 2.5,Apache 2.4.9和MySQL 5.6.17上进行.

The problematic version is PHP 7.1.9, the other versions I tried that work OK are 5.5.12 and 7.0.23. All of the test were conducted on WAMP 2.5 with Apache 2.4.9 and MySQL 5.6.17.

这里是复制它的最少代码.

Here is a minimun set of code to replicate it.

创建表和初始数据:

DROP TABLE IF EXISTS `test_bit`;
CREATE TABLE IF NOT EXISTS `test_bit` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `bit_col` BIT(1) NOT NULL DEFAULT FALSE,
  `varchar_col` VARCHAR(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci;

INSERT INTO test_bit (bit_col, varchar_col)
VALUES (1, 'hello'), (0, 'world'), (TRUE, 'how'), (FALSE, 'are'), (NULL, 'you?');

这是PHP代码:

<?php
$db = mysqli_connect("127.0.0.1", "root", "", "test_db");
$result = mysqli_query($db, "SELECT * FROM test_bit");
$rs = array();
while ($row = mysqli_fetch_assoc($result)) {
    $rs[] = $row;
}
var_dump($rs);
mysqli_free_result($result);

这是PHP 5.5和7.0的结果

Here are the results in PHP 5.5 and 7.0

array (size=5)
  0 => 
    array (size=3)
      'id' => string '1' (length=1)
      'bit_col' => string '1' (length=1)
      'varchar_col' => string 'hello' (length=5)
  1 => 
    array (size=3)
      'id' => string '2' (length=1)
      'bit_col' => string '0' (length=1)
      'varchar_col' => string 'world' (length=5)
  2 => 
    array (size=3)
      'id' => string '3' (length=1)
      'bit_col' => string '1' (length=1)
      'varchar_col' => string 'how' (length=3)
  3 => 
    array (size=3)
      'id' => string '4' (length=1)
      'bit_col' => string '0' (length=1)
      'varchar_col' => string 'are' (length=3)
  4 => 
    array (size=3)
      'id' => string '5' (length=1)
      'bit_col' => string '0' (length=1)
      'varchar_col' => string 'you?' (length=4)

这是PHP 7.1的结果

And here is the result in PHP 7.1

array (size=5)
  0 => 
    array (size=3)
      'id' => string '1' (length=1)
      'bit_col' => string '326352660489830401' (length=18)
      'varchar_col' => string 'hello' (length=5)
  1 => 
    array (size=3)
      'id' => string '2' (length=1)
      'bit_col' => string '326352866648260608' (length=18)
      'varchar_col' => string 'world' (length=5)
  2 => 
    array (size=3)
      'id' => string '3' (length=1)
      'bit_col' => string '326353072806690817' (length=18)
      'varchar_col' => string 'how' (length=3)
  3 => 
    array (size=3)
      'id' => string '4' (length=1)
      'bit_col' => string '326353278965121024' (length=18)
      'varchar_col' => string 'are' (length=3)
  4 => 
    array (size=3)
      'id' => string '5' (length=1)
      'bit_col' => string '326353485123551232' (length=18)
      'varchar_col' => string 'you?' (length=4)

我将PHP 7.1设置为服务器版本后,PHP 7.1的'bit_col'中的数字第一次或两次更改,然后保持不变(直到我更改为7.0或5.5,然后再次回到7.1).它们看起来像是时间戳记或类似的东西.

The numbers in the 'bit_col' in PHP 7.1 change the first one or two times I set PHP 7.1 as my server version and then stay the same (until I change to 7.0 or 5.5 and then come back to 7.1 again). They seem like a timestamp or something of the sort.

任何帮助将不胜感激.

推荐答案

事实上,自8月1日以来,这已经是PHP中已报告的问题.

It is in fact an already reported issue in PHP since August the 1st.

PHP 错误#75018

正如一些评论所建议的那样,它似乎仅适用于Windows平台.

It seems to be only for the Windows Platform as some comments have suggested.

这篇关于MySql位列在PHP 7.1中返回怪异的大量数字(在以前的版本中不如此)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆