Changeset 1786


Ignore:
Timestamp:
Feb 7, 2007, 8:49:35 PM (17 years ago)
Author:
laurent_duretz
Message:
 
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r1763 r1786  
    522522function mass_inserts($table_name, $dbfields, $datas)
    523523{
     524  global $conf;
     525
    524526  if (count($datas) != 0)
    525527  {
    526528    // inserts all found categories
    527     $query = '
     529    $query_begin = '
    528530  INSERT INTO '.$table_name.'
    529531    ('.implode(',', $dbfields).')
    530532     VALUES';
    531     $first = 1;
     533
     534    $first = true;
     535    $query_value = array();
     536    $query_value_index = 0;
     537
    532538    foreach ($datas as $insert)
    533539    {
    534       $query.= '
     540      $query_value[$query_value_index] .= '
    535541    ';
    536542      if ($first)
    537543      {
    538         $first = 0;
     544        $first = false;
     545        if (strlen($query_value[$query_value_index]) > 6)
     546        {
     547          $query_value[$query_value_index] .= ',';
     548        }
    539549      }
    540550      else
    541551      {
    542         $query.= ',';
     552        if (strlen($query_value[$query_value_index]) >= $conf['max_allowed_packet'])
     553        {
     554          $query_value_index ++;
     555          $query_value[$query_value_index] .= '
     556    ';
     557          $first = true;
     558        }
     559        else
     560        {
     561          $query_value[$query_value_index] .= ',';
     562        }
    543563      }
    544       $query.= '(';
     564      $query_value[$query_value_index] .= '(';
    545565      foreach ($dbfields as $field_id => $dbfield)
    546566      {
    547567        if ($field_id > 0)
    548568        {
    549           $query.= ',';
     569          $query_value[$query_value_index] .= ',';
    550570        }
    551571
    552572        if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
    553573        {
    554           $query.= 'NULL';
     574          $query_value[$query_value_index] .= 'NULL';
    555575        }
    556576        else
    557577        {
    558           $query.= "'".$insert[$dbfield]."'";
     578          $query_value[$query_value_index] .= "'".$insert[$dbfield]."'";
    559579        }
    560580      }
    561       $query.=')';
    562     }
    563     $query.= '
    564 ;';
    565     pwg_query($query);
     581      $query_value[$query_value_index] .= ')';
     582    }
     583   
     584    $query_end .= '
     585;';
     586    foreach ($query_value as $value)
     587    {
     588      $final_query = $query_begin.$value.$query_end;
     589      pwg_query($final_query);
     590    }
    566591  }
    567592}
  • trunk/include/config_default.inc.php

    r1781 r1786  
    665665$conf['light_slideshow'] = true; 
    666666
     667// +-----------------------------------------------------------------------+
     668// |                                mysql                                  |
     669// +-----------------------------------------------------------------------+
     670
     671// $conf['max_allowed_packet'] indicates the max size in octets of MySql
     672// request. Used in mass_inserts() function.
     673$conf['max_allowed_packet'] = 1000000;
     674
    667675?>
Note: See TracChangeset for help on using the changeset viewer.