Problem with PHP mysql bigint

I have two tables with bigint:

table1 id bigint(20) PK autoincrement name varchar(40), text table2 id bigint(20) PK autoincrement created datetime text_field id_table1_ref bigint(20) 

After inserting data into table1 and trying to insert table1.id into table2.id_table1_ref, the number is different, that is:

The number 1552545662588 from table1.t1 becomes 1552545662 or, even worse, a negative number.

I know this is a configuration issue, but I can't figure out how to do this. I tried setting signed / unrecognized values ​​for fields, but it does not work.

This happens on my local UNIX machine, everything is working fine on the server, at least for now.

Any help would be greatly appreciated.

+4
source share
3 answers

You need to convert it to a string in SQL before injecting it into PHP. In PHP, you can use GMP to process numbers.

MySQL docs for conversion: http://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert

+3
source

This is also the case when PHP, at least on some 64-bit operating systems (for example, FreeBSD AMD64) uses an 8-byte int, which is checked when testing with

echo 'Size int is'.PHP_INT_SIZE;

So, if you are going to work only with a 64-bit operating system, you do not need to control BIGINT as strings in PHP.

+3
source

I solved this problem by switching to another version of php, which is changing from a 64-bit version of php to a 32-bit version of php. It really works for me.

-2
source

Source: https://habr.com/ru/post/1479132/


All Articles