Resolves issue #2081 : provides an option to include statements to disable and re-enable foreign key checks in a MySQL database backup output statement.
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index c4140ae..3ed7596 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -326,7 +326,8 @@
'format' => 'gzip', // gzip, zip, txt
'add_drop' => TRUE,
'add_insert' => TRUE,
- 'newline' => "\n"
+ 'newline' => "\n",
+ 'fk_checks' => TRUE
);
// Did the user submit any preferences? If so set them....
diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php
index 8aa0517..e2de82d 100644
--- a/system/database/drivers/mysql/mysql_utility.php
+++ b/system/database/drivers/mysql/mysql_utility.php
@@ -76,6 +76,13 @@
// Build the output
$output = '';
+
+ // Do we need to include a statement to disable FK checks?
+ if ($fk_checks === FALSE)
+ {
+ $output .= "SET foreign_key_checks = 0;".$newline;
+ }
+
foreach ( (array) $tables as $table)
{
// Is the table in the "ignore" list?
@@ -181,6 +188,12 @@
$output .= $newline.$newline;
}
+ // Do we need to include a statement to re-enable FK checks?
+ if ($fk_checks === FALSE)
+ {
+ $output .= "SET foreign_key_checks = 1;".$newline;
+ }
+
return $output;
}
diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php
index 345691e..ff49490 100644
--- a/system/database/drivers/mysqli/mysqli_utility.php
+++ b/system/database/drivers/mysqli/mysqli_utility.php
@@ -76,6 +76,13 @@
// Build the output
$output = '';
+
+ // Do we need to include a statement to disable FK checks?
+ if ($fk_checks === FALSE)
+ {
+ $output .= "SET foreign_key_checks = 0;".$newline;
+ }
+
foreach ( (array) $tables as $table)
{
// Is the table in the "ignore" list?
@@ -181,6 +188,12 @@
$output .= $newline.$newline;
}
+ // Do we need to include a statement to re-enable FK checks?
+ if ($fk_checks === FALSE)
+ {
+ $output .= "SET foreign_key_checks = 1;".$newline;
+ }
+
return $output;
}