diff --git a/src/MySQLDump.php b/src/MySQLDump.php index cf6a8a9..bf78cc4 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,20 @@ 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'"); + 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, "DELIMITER ;\n\n"); + } + $res->close(); + } fwrite($handle, "\n"); }