|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DB; |
|
4
|
|
|
|
|
5
|
|
|
use Filemanager\file; |
|
6
|
|
|
|
|
7
|
|
|
class manager |
|
8
|
|
|
{ |
|
9
|
|
|
public function backup_tables($host, $user, $pass, $name, $nama_file, $tables = '*') |
|
10
|
|
|
{ |
|
11
|
|
|
$link = mysqli_connect($host, $user, $pass); |
|
|
|
|
|
|
12
|
|
|
$return = 'SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; |
|
13
|
|
|
SET AUTOCOMMIT = 0; |
|
14
|
|
|
START TRANSACTION; |
|
15
|
|
|
SET time_zone = "+00:00"; |
|
16
|
|
|
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; |
|
17
|
|
|
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; |
|
18
|
|
|
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; |
|
19
|
|
|
/*!40101 SET NAMES utf8mb4 */;'; |
|
20
|
|
|
mysqli_select_db($link, $name); |
|
21
|
|
|
if ('*' == $tables) { |
|
22
|
|
|
$tables = []; |
|
23
|
|
|
$result = mysqli_query($link, 'SHOW TABLES'); |
|
24
|
|
|
while ($row = mysqli_fetch_row($result)) { |
|
|
|
|
|
|
25
|
|
|
$tables[] = $row[0]; |
|
26
|
|
|
} |
|
27
|
|
|
} else { |
|
28
|
|
|
$tables = is_array($tables) ? $tables : explode(',', $tables); |
|
29
|
|
|
} |
|
30
|
|
|
foreach ($tables as $table) { |
|
31
|
|
|
$result = mysqli_query($link, 'SELECT * FROM ' . $table); |
|
32
|
|
|
$num_fields = mysqli_num_fields($result); |
|
|
|
|
|
|
33
|
|
|
$return .= 'DROP TABLE IF EXISTS `' . $table . '`;'; |
|
34
|
|
|
$row2 = mysqli_fetch_row(mysqli_query($link, 'SHOW CREATE TABLE ' . $table)); |
|
35
|
|
|
$return .= "\n\n" . $row2[1] . ";\n\n"; |
|
36
|
|
|
for ($i = 0; $i < $num_fields; ++$i) { |
|
37
|
|
|
while ($row = mysqli_fetch_row($result)) { |
|
38
|
|
|
$return .= 'INSERT INTO `' . $table . '` VALUES('; |
|
39
|
|
|
for ($j = 0; $j < $num_fields; ++$j) { |
|
40
|
|
|
$row[$j] = addslashes($row[$j]); |
|
41
|
|
|
$row[$j] = str_replace("\n", '\\n', $row[$j]); //ereg_replace |
|
42
|
|
|
if (isset($row[$j])) { |
|
43
|
|
|
$return .= '"' . $row[$j] . '"'; |
|
44
|
|
|
} else { |
|
45
|
|
|
$return .= '""'; |
|
46
|
|
|
} |
|
47
|
|
|
if ($j < ($num_fields - 1)) { |
|
48
|
|
|
$return .= ','; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
$return .= ");\n"; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
$return .= "\n\n\n"; |
|
55
|
|
|
} |
|
56
|
|
|
$return .= '/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; |
|
57
|
|
|
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; |
|
58
|
|
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
|
59
|
|
|
'; |
|
60
|
|
|
file::file(__DIR__ . '/backup/' . str_replace('.sql', '', $nama_file) . '.sql', $return, true); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
return $return; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.