gpt4 book ai didi

phpMyAdmin - 大整型值始终以零结尾

转载 作者:行者123 更新时间:2023-11-29 17:58:24 25 4
gpt4 key购买 nike

当插入像 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

最佳答案

解决方案已找到,这个问题是由于json_decode()造成的,JSON_BIGINT_AS_STRING应该作为参数传递

options
Bitmask of JSON decode options. Currently there are two supported options. The first is JSON_BIGINT_AS_STRING that allows casting big integers to string instead of floats which is the default.

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

Example #5 json_decode() of large integers

<?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

关于phpMyAdmin - 大整型值始终以零结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48609882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com