From e681c4e7357771ddd806639d31ede293064c9160 Mon Sep 17 00:00:00 2001 From: Abu Dzakiyyah Date: Thu, 1 Apr 2021 04:15:53 +0800 Subject: [PATCH 1/2] Add Mysql Function Backup Still testing --- src/MySQLDump.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/MySQLDump.php b/src/MySQLDump.php index cf6a8a9..7e02cbd 100644 --- a/src/MySQLDump.php +++ b/src/MySQLDump.php @@ -16,7 +16,8 @@ class MySQLDump public const CREATE = 2; public const DATA = 4; public const TRIGGERS = 8; - public const ALL = 15; // DROP | CREATE | DATA | TRIGGERS + public const FUNCTIONS = 16; + public const ALL = 31; // DROP | CREATE | DATA | TRIGGERS | FUNCTIONS private const MAX_SQL_SIZE = 1e6; @@ -202,6 +203,19 @@ public function dumpTable($handle, $table): void } $res->close(); } + + //STILL TEST + if ($mode & self::FUNCTIONS) { + $res = $this->connection->query("SHOW FUNCTION STATUS WHERE Security_type='DEFINER'"); + fwrite($handle, "DELIMITER ;;\n\n"); + while ($rows = $res->fetch_assoc()) { + $row = $this->connection->query("SHOW CREATE FUNCTION {$this->delimite($rows['Name'])}"); + $func = $row->fetch_assoc(); + fwrite($handle, $func['Create Function']. "$$;\n\n"); + } + fwrite($handle, "DELIMITER ;\n\n"); + $res->close(); + } fwrite($handle, "\n"); } From 211a8aa6f923772406cebc17b17007e1fa177b4c Mon Sep 17 00:00:00 2001 From: Abu Dzakiyyah Date: Thu, 1 Apr 2021 05:54:46 +0800 Subject: [PATCH 2/2] Update result file handle Still duplicated --- src/MySQLDump.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/MySQLDump.php b/src/MySQLDump.php index 7e02cbd..bf78cc4 100644 --- a/src/MySQLDump.php +++ b/src/MySQLDump.php @@ -207,13 +207,14 @@ public function dumpTable($handle, $table): void //STILL TEST if ($mode & self::FUNCTIONS) { $res = $this->connection->query("SHOW FUNCTION STATUS WHERE Security_type='DEFINER'"); - fwrite($handle, "DELIMITER ;;\n\n"); while ($rows = $res->fetch_assoc()) { + fwrite($handle, "DROP FUNCTION IF EXISTS {$this->delimite($rows['Name'])};\n"); + fwrite($handle, "DELIMITER ;;\n"); $row = $this->connection->query("SHOW CREATE FUNCTION {$this->delimite($rows['Name'])}"); $func = $row->fetch_assoc(); - fwrite($handle, $func['Create Function']. "$$;\n\n"); + fwrite($handle, $func['Create Function']. "\n;;\n"); + fwrite($handle, "DELIMITER ;\n\n"); } - fwrite($handle, "DELIMITER ;\n\n"); $res->close(); }