I have an ID system with PHP. It generates a 12 digit ID this way:
// create a 12 digit ID
function createTwelveId(){
$digit_1 = rand(0, 9);
$digit_2 = rand(0, 9);
$digit_3 = rand(0, 9);
$digit_4 = rand(0, 9);
$digit_5 = rand(0, 9);
$digit_6 = rand(0, 9);
$digit_7 = rand(0, 9);
$digit_8 = rand(0, 9);
$digit_9 = rand(0, 9);
$digit_10 = rand(0, 9);
$digit_11 = rand(0, 9);
$digit_12 = rand(0, 9);
$pre_twelve_id = $digit_1 . $digit_2 . $digit_3 . $digit_4 . $digit_5 . $digit_6 . $digit_7 . $digit_8 . $digit_9 . $digit_10 . $digit_11 . $digit_12;
return $pre_twelve_id;
}
When called, it is like this:
$comment_ID = createTwelveId();
And then it is inserted into my database this way:
//create comment
$sentence = $connection->prepare("
INSERT INTO comments (ID)
VALUES (:ID)
");
$sentence->execute(array(
':ID' => $comment_ID
));
But every time I check the result on the database, it always inserts this:
004294967295
Please notice on this column I have Zerofill
and Unsigned
values on, that's why the int has 2 zeros at the beginning. And when I remove the Zerofill
and Unsigned
values, it inserts this:
2147483647
It always does this. Isn't it supposed to insert a random int into the database instead of those 2 numbers?
How can I stop this from happening and instead of those 2, insert the real random characters?
Aucun commentaire:
Enregistrer un commentaire