AFS AFS - 5 months ago 19
MySQL Question

PDO insert a differnet int value

I'm inserting on a database with PDO but the inserted integer value is different than the expected

$insert = $con->prepare("INSERT INTO usuarios(id,username,token)
VALUES (:id,:username,:token)");
echo $inst->getUser_Id();//here shows the correct value
echo $inst->getUser_Id();//here shows the correct value too

When I check the inserted data ,the field id is different than
echo $inst->getUser_Id()


The issue is that the id field is declared as signed integer, which has a maximum value of 2147483647. Since you try to insert a bigger value than the max and apparently the strict sql mode is turned off, mysql rounds the data down to the maximum. In the int(20) declaration the 20 does not influence the maximum value the field can hold. Change the datatype to bigint or unsigned int and you will be fine.