phpMyAdmin - 大的int值总是以零结尾

时间:2018-02-04 15:43:36

标签: php mysql phpmyadmin

当插入像1591823907560714这样的值时,它总是以零结尾

(1591866907560700)在我的数据库中,我不知道为什么。我使用bigint作为

数据类型,这是我的sql语句:

$ user = json_decode(file_get_contents(“php:// input”));

// cast the object to an array
$user = (array)$user;

$userId = $user['id'];

$firstname = $user['firstName'];
$lastname = $user['lastName'];
$email = $user['email'];
$photoUrl = $user['photoUrl'];

$createUser = "INSERT INTO users (userId, firstname, lastname, email, photoUrl, phoneNumber) 
                       VALUES ('".$userId."','$firstname','$lastname','$email','$photoUrl',NULL)";

我应该在插入之前解析或格式化数字吗?

enter image description here

1 个答案:

答案 0 :(得分:0)

解决方法发现,这个问题是由于json_decode(),JSON_BIGINT_AS_STRING应该作为参数传递

  

选项
JSON解码选项的位掩码。目前有两个   支持的选项。第一个是允许的JSON_BIGINT_AS_STRING   将大整数转换为字符串而不是浮动,这是默认值。

http://php.net/manual/en/function.json-decode.php

  

示例#5大整数的json_decode()

<?php
$json = '{"number": 12345678901234567890}';

var_dump(json_decode($json));
var_dump(json_decode($json, false, 512, JSON_BIGINT_AS_STRING));

?>
The above example will output:

object(stdClass)#1 (1) {
  ["number"]=>
  float(1.2345678901235E+19)
}
object(stdClass)#1 (1) {
  ["number"]=>
  string(20) "12345678901234567890"
}

现在该值已正确插入为1591866907560714