aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--admin/include/functions.php57
-rw-r--r--include/config_default.inc.php8
2 files changed, 29 insertions, 36 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index c3494d266..7bc9cf5e6 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -521,60 +521,61 @@ 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_begin = '
-INSERT INTO '.$table_name.'
- ('.implode(',', $dbfields).')
- VALUES';
-
$first = true;
- $query_value = '';
-
+
+ $query = 'SHOW VARIABLES where variable_name = \'max_allowed_packet\';';
+ list(, $packet_size) = mysql_fetch_row(pwg_query($query));
+ $packet_size = $packet_size - 2000; // The last list of values MUST not exceed 2000 character
+
foreach ($datas as $insert)
{
+ if (strlen($query) >= $packet_size)
+ {
+ $query .= '
+;';
+ pwg_query($query);
+ $first = true;
+ }
+
if ($first)
{
+ $query = '
+ INSERT INTO '.$table_name.'
+ ('.implode(',', $dbfields).')
+ VALUES';
$first = false;
}
else
{
- if (strlen($query_value) >= $conf['max_allowed_packet'])
- {
- pwg_query( $query_begin.$query_value );
- $query_value = '';
- }
- else
- {
- $query_value .= ',';
- }
+ $query .= '
+ , ';
}
-
- $query_value .= '
- (';
-
+
+ $query .= '(';
foreach ($dbfields as $field_id => $dbfield)
{
if ($field_id > 0)
{
- $query_value .= ',';
+ $query .= ',';
}
if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
{
- $query_value .= 'NULL';
+ $query .= 'NULL';
}
else
{
- $query_value .= "'".$insert[$dbfield]."'";
+ $query .= "'".$insert[$dbfield]."'";
}
}
- $query_value .= ')';
+ $query .= ')';
}
- pwg_query($query_begin.$query_value);
+
+ $query .= '
+;';
+ pwg_query($query);
}
}
diff --git a/include/config_default.inc.php b/include/config_default.inc.php
index b93f3e51d..110accd46 100644
--- a/include/config_default.inc.php
+++ b/include/config_default.inc.php
@@ -677,12 +677,4 @@ $conf['filter_pages'] = array
// Every plugin from 1.7 would be design to manage light_slideshow case.
$conf['light_slideshow'] = true;
-// +-----------------------------------------------------------------------+
-// | mysql |
-// +-----------------------------------------------------------------------+
-
-// $conf['max_allowed_packet'] indicates the max size in octets of MySql
-// request. Used in mass_inserts() function.
-$conf['max_allowed_packet'] = 1000000;
-
?>