I've recently been researching the cause of an issue that involved inconsistency in inserting a 32-bit unsigned integer into a signed 32-bit integer column in MySQL using PHP 5.2.x and PDO. The result is that any code shared between 32-bit and 64-bit platforms that inserts values above 2 billion and change into a signed integer column in MySQL has to be normalized before insertion.

If MySQL expects a 32-bit signed integer,the following has to be done or MySQL will (sort of) truncate the value at 2^31-1:

if ($val > 2147483647) { /* if value is greater than 2^31-1 */
    $val -= 4294967296; /* Emulate 32-bit signed overflow by subtracting 2^32 */
}

Of course, if the value to be inserted is 32-bit unsigned or greater than 32-bit, that's another story.

On a 32-bit platform, this isn't a problem: the 32-bit number wraps and the binary representations match. On 64-bit platforms, the behavior is not consistent due to what I believe is a bug in PDO... PDO 1.0.3 on a 64-bit machine seems to emulate 32-bit behavior, so 'UPDATE x SET int32_field=?' results in a number from -2^31 to 2^31-1. In later versions of PDO (Debian > 4.0 and Ubuntu >= 8.10) the behavior is corrected on 64-bit platforms: PDO will send signed integers above 2^31-1 on a 64-bit platform as their actual value (and will not wrap them).

Practically, this means 'UPDATE x SET int32_field=?' yeilds the following results:

32-bit machine or a 64-bit machine with PDO <= 1.0.3: * 1000000000 => 1000000000 * 2000000000 => 2000000000 * 3000000000 => -1294967296 * 4000000000 => -294967296

64-bit machine with PDO > 1.0.3: * 1000000000 => 1000000000 * 2000000000 => 2000000000 * 3000000000 => 2147483647 * 4000000000 => 2147483647

I think that's about it. Hopefully my math is right...