diff options
author | laurent.duretz <laurent.duretz@piwigo.org> | 2007-02-07 19:49:35 +0000 |
---|---|---|
committer | laurent.duretz <laurent.duretz@piwigo.org> | 2007-02-07 19:49:35 +0000 |
commit | 15b3774482b086f4f34f440763d11d00f7e2b04e (patch) | |
tree | ea949e2caa57fe9ea3100544a6bcf92aafb218af /admin/include | |
parent | e3c6370b8d1bfa8a491bca51bcb8655021ac4da9 (diff) |
git-svn-id: http://piwigo.org/svn/trunk@1786 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin/include')
-rw-r--r-- | admin/include/functions.php | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php index a7fd10e36..2e3b428f8 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -521,48 +521,73 @@ function get_fs_directories($path, $recursive = true) */ function mass_inserts($table_name, $dbfields, $datas) { + global $conf; + if (count($datas) != 0) { // inserts all found categories - $query = ' + $query_begin = ' INSERT INTO '.$table_name.' ('.implode(',', $dbfields).') VALUES'; - $first = 1; + + $first = true; + $query_value = array(); + $query_value_index = 0; + foreach ($datas as $insert) { - $query.= ' + $query_value[$query_value_index] .= ' '; if ($first) { - $first = 0; + $first = false; + if (strlen($query_value[$query_value_index]) > 6) + { + $query_value[$query_value_index] .= ','; + } } else { - $query.= ','; + if (strlen($query_value[$query_value_index]) >= $conf['max_allowed_packet']) + { + $query_value_index ++; + $query_value[$query_value_index] .= ' + '; + $first = true; + } + else + { + $query_value[$query_value_index] .= ','; + } } - $query.= '('; + $query_value[$query_value_index] .= '('; foreach ($dbfields as $field_id => $dbfield) { if ($field_id > 0) { - $query.= ','; + $query_value[$query_value_index] .= ','; } if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') { - $query.= 'NULL'; + $query_value[$query_value_index] .= 'NULL'; } else { - $query.= "'".$insert[$dbfield]."'"; + $query_value[$query_value_index] .= "'".$insert[$dbfield]."'"; } } - $query.=')'; + $query_value[$query_value_index] .= ')'; } - $query.= ' + + $query_end .= ' ;'; - pwg_query($query); + foreach ($query_value as $value) + { + $final_query = $query_begin.$value.$query_end; + pwg_query($final_query); + } } } |