开发者

Drupal function db_query() stores overflow value for INTs that are not too large

I have this code inside of a exit hook in a custom module:

$diff = round(((microtime(true)-$script_start_time)*1000));
watchdog('thaty', $diff);
    if(variable_get('thingy', 0) == 1) {
        $data = array(
           'q'=>$_GET['q'],
           'memory'=>memory_get_peak_usage(),
           'executio开发者_Go百科n_time'=>$diff
        );
        db_query('INSERT INTO {blah} (q,memory,dt,execution_time) VALUES (\'%s\',%b,UNIX_TIMESTAMP(),%b)',$data);
    }

The value of $diff will occasionally consistently get saved in the database as 2147483647, which is the overflow value for an INT, I believe, in PHP. When I log the value via watchdog I can confirm that it does not get set to 2147483647, but the real value, which is a three digit whole number.

Typical values (confirmed from logging):

  • 708
  • 408
  • 413

The execution_time column is int(11).

I can't seem to find the source of this issue. Things I've tried:

  • Using %d instead of %b for the value
  • Assigning $diff to a new an INT variable
  • Checking for this wrong value pre-insert
  • Confirming the value of $diff is not too large for an INT in PHP
  • Tried using %n, re: http://www.lullabot.com/articles/drupocalypse-now-or-dangerous-integer-handling-drupal-write-record


It seems db_query("INSERT....") is deprecated in favour of drupal_write_record().

Try drupal_write_record().

Seeing as this is most certainly a masking problem when building the query (rather than a database problem), maybe that does it better.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜