PDO插入不同的int值

时间:2016-08-27 18:08:15

标签: php mysql pdo

我在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()

不同

1 个答案:

答案 0 :(得分:1)

问题是id字段被声明为有符号整数,其maximum value为2147483647.由于你试图插入一个比max更大的值,显然严格的sql模式被关闭,mysql回合数据下降到最大值。在int(20)声明中{20} does not influence the maximum value the field can hold。将数据类型更改为bigint或unsigned int,您将没事。