I have a mysql database and a table to store stuff from twitter API. When i parse data with PHP from twitter i use mysql_query to insert data into the table.
I have a weird problem with the ID of the tweets:
For example the status update with ID 15861323074113537 (a tweet from google) is stored in the database as: 15861323074114000 (the last 4 digits are altered).
The php query is:
$sql = mysql_query("INSERT INTO $table (id,tw_text) VALUES ($id,'$tw_text')");
If i edit the record via phpmyadmin the correct value is stored (15861323074113537). The column is BIGINT.
So i guess something weird is going on with the php function mysql_query and the INSERT command.
Any ideas/solutions?
Thanks in advance
ok found the problem, it wasn't code related. Twitter returns 2 IDs and one of those has 000 in the end. [id_str] => 15861323074113537 and [id] => 15861323074114000
Damn twitter API!
Sorry for the trouble :/
PHP integers cannot be that large. When a number that doesn't fit into an integer is used, it is converted to a float. What you are probably seeing is that even the float is not precise enough to contain that many digits. Follow webbiedave's advice and keep it as a string to avoid rounding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With