bigint truncated via PDO?

Viewed 2622

I came across a problem with storing a large integer in a BIGINT column on MySQL via PDO

If i run this test:

$number = "30123456789";
var_dump($number); //prints string(11) "30123456789"

$new_number = (int)$number;
var_dump($new_number); //prints int(30123456789) 

So far so good...

If I run this SQL directly in MySQL:

update my_table set bigint_field = 30123456789 where id_field = 1

Everything works fine...

The problem arise when I try to save that number via PDO and I reduced the problem to this line of code:

//parameterized query
//update my_table set bigint_field = :bigint_field where id_field = :id_field
$statement->bindValue(":bigint_field", $new_number, PDO::PARAM_INT);

If the optional third type parameter is absent or equals PDO::PARAM_STR then the value is saved jut fine, if not the value is truncated to 58685709. If I try to save 20288976024, the value is truncated to 0. What is happening here

I'm running PHP 5.5.33 and MySQL 5.6.25 on Debian Wheezy x64

1 Answers
Related