Index: includes/database.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/Attic/database.inc,v
retrieving revision 1.92.2.4
diff -u -p -r1.92.2.4 database.inc
--- includes/database.inc	16 Feb 2009 14:41:58 -0000	1.92.2.4
+++ includes/database.inc	29 Jul 2009 16:13:04 -0000
@@ -207,8 +207,21 @@ function _db_query_callback($match, $ini
   }
 
   switch ($match[1]) {
-    case '%d': // We must use type casting to int to convert FALSE/NULL/(TRUE?)
-      return (int) array_shift($args); // We don't need db_escape_string as numbers are db-safe
+    case '%d':
+      $value = array_shift($args);
+      // Do we need special bigint handling? This solution works for 53 bits.
+      if ($value > PHP_INT_MAX) {
+        $precision = ini_get('precision');
+        @ini_set('precision', 16);
+        $value = sprintf('%.0f', $value);
+        @ini_set('precision', $precision);
+      }
+      else {
+        // We must use type casting to int to convert FALSE/NULL/TRUE
+        $value = (int) $value;
+      }
+      // We don't need db_escape_string as numbers are db-safe.
+      return $value;
     case '%s':
       return db_escape_string(array_shift($args));
     case '%n':
