Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/MySQLDump.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -130,6 +131,20 @@ public function dumpTable($handle, $table): void

$view = isset($row['Create View']);

if ($view && ($mode & self::FUNCTIONS)) {
$db = $this->connection->query('SELECT DATABASE()')->fetch_row();
$fres = $this->connection->query("SHOW FUNCTION STATUS WHERE Db='$db[0]'");
while ($rows = $fres->fetch_assoc()) {
fwrite($handle, "DROP FUNCTION IF EXISTS {$this->delimite($rows['Name'])};\n");
fwrite($handle, "DELIMITER ;;\n\n");
$frow = $this->connection->query("SHOW CREATE FUNCTION {$this->delimite($rows['Name'])}");
$func = $frow->fetch_assoc();
fwrite($handle, $func['Create Function']. "\n;;\n\n");
fwrite($handle, "DELIMITER ;\n\n");
}
$fres->close();
}

if ($mode & self::DROP) {
fwrite($handle, 'DROP ' . ($view ? 'VIEW' : 'TABLE') . " IF EXISTS $delTable;\n\n");
}
Expand Down