2

I'm using php-activerecord to manage my MySQL entries.

The block of code where the problem ocurs is the following:

$item->id = $result->id;
$item->save();

var_dump($result->id); // string(10) "2386737351" 
var_dump($item->id);   // int(2147483647)

The problem is that $result->id is string(10) "2386737351" like it should, but $item->id becomes int(2147483647). My column id is of type BIGINT, so no problem there.

It looks like php-activerecord converts that value to a int again which is capped at it's maximum value of 2147483647.

Obviously this is terribly wrong and causes Duplicate entry '2147483647' for key 'unique'.

How can I overcome this?

bockzior
  • 536
  • 1
  • 7
  • 19
  • why would assigning a value to $item->id convert it to int? Is this *really* the code at cause? but nevertheless, can php really manage 64bit integers? I thought I heard someone comment it couldn't, and should manage such numbers as strings – Félix Adriyel Gagnon-Grenier May 20 '15 at 02:01

2 Answers2

1

Native 64-bit integers require 64-bit hardware AND the 64-bit version of PHP.

On 32-bit hardware: $ php -r 'echo PHP_INT_MAX;' 2147483647

On 64-bit hardware: $ php -r 'echo PHP_INT_MAX;' 9223372036854775807

As said by scotts on this question : how to have 64 bit integer on PHP?

So you have to use PHP 64bits version to use BIGINTs, else they will be automatically (or not and you will get an error) converted to integer.

Fraligatorus
  • 59
  • 1
  • 10
1

Your BIGINT is being cast to an int because of the setting in column.php. While the "real solution" would be to run a 64 bit system, if you cannot, the other thing might be to just stop the cast from happening

Look at line 37 in column.php , I suggest you change that. I haven't tried it myself, but I suppose that this does the trick:

'bigint'    => self::STRING,
Nanne
  • 64,065
  • 16
  • 119
  • 163