我插入一个数据库与PDO,但插入的整数值不同于预期的
$insert = $con->prepare("INSERT INTO usuarios(id,username,token)
VALUES (:id,:username,:token)");
echo $inst->getUser_Id();//here shows the correct value
$insert->bindparam(':id',$inst->getUser_Id(),PDO::PARAM_INT);
$insert->bindparam(':username',$inst->getUsername());
$insert->bindparam(':token',$inst->getToken());
$insert->execute();
echo $inst->getUser_Id();//here shows the correct value too
当我检查插入的数据时,字段id与echo $inst->getUser_Id()
问题是id字段被声明为有符号整数,其最大值为2147483647。由于您尝试插入比最大值更大的值,并且显然关闭了严格的sql模式,mysql将数据舍入到最大值。在int(20)
声明中,20不影响该字段所能容纳的最大值。将数据类型更改为bigint或unsigned int,就可以了。