Bonjour, voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
$title = "MySQL Backup";
 
// Your settings here
 
$db_host = $db_host; 
$db_user = $_SESSION['username']; 
$db_pw   = $_SESSION['password']; 
$db_name = $_GET['db']; 
$path = $row_User['homedir'] . '/_Backups/'; 
 
if (!is_dir($path)) 
{ 
	mkdir($path, 0777);
} 
 
echo "<b>Database Backup</b><br>";
 
$database = $db_name; 
$counter = 0; 
$file_name = $path.$database."_".date("Y-m-d_H-i").".sql"; 
 
$connection = @mysql_connect($db_host,$db_user,$db_pw); 
@mysql_select_db($db_name,$connection); 
 
$text  = "# --------------------------------------------------------\r\n";
$text .= "# DATABASE DUMP\r\n"; 
$text .= "# Host: ".$db_host."\r\n"; 
$text .= "# Time: ".date("d. F Y")." um ".date("H:i")."\r\n"; 
$text .= "# Running on: ".php_uname()."\r\n"; 
$text .= "# MySQL-Version: ".mysql_get_server_info()."\r\n"; 
$text .= "# PHP-Version: ".phpversion()."\r\n"; 
$text .= "# Database: `$database`\r\n"; 
$text .= "# --------------------------------------------------------\r\n\r\n"; 
 
$fd = fopen($file_name,"a+"); 
fwrite($fd, $text); 
fclose($fd); 
 
$c = 0; 
$result2 = @mysql_list_tables($database); 
 
for ($i = 0; $i < @mysql_num_rows($result2); $i++) 
{ 
    $table = @mysql_tablename($result2,$i); 
    if ($table != "") { 
        $tbl_array[$c] = @mysql_tablename($result2,$i); 
        $c++; 
        $counter++; 
    } 
 
} 
 
for ($y = 0; $y < $c; $y++) { 
    $table = $tbl_array[$y]; 
 
    unset($def,$index); 
    $def .= "DROP TABLE IF EXISTS $table;\r\n"; 
    $def .= "CREATE TABLE $table (\r\n"; 
    $result3 = @mysql_db_query($database, "SHOW FIELDS FROM $table"); 
    while ($row = @mysql_fetch_array($result3)) { 
        $def .= "    ".$row["Field"]." ".$row["Type"]; 
        if ($row["Default"] != "") { $def .= " DEFAULT '".$row["Default"]."'"; } 
        if ($row["Null"] != "YES") { $def .= " NOT NULL"; } 
        if ($row["Extra"] != "") { $def .= " ".$row["Extra"]; } 
        $def .= ",\r\n"; 
    } 
    $def = ereg_replace(",\r\n$", "", $def); 
    $result3 = @mysql_db_query($database, "SHOW KEYS FROM $table"); 
    while ($row = @mysql_fetch_array($result3)) { 
        $kname = $row["Key_name"]; 
        if (($kname != "PRIMARY") && ($row["Non_unique"] == 0)) { $kname = "UNIQUE|".$kname; } 
        if (!isset($index[$kname])) { $index[$kname] = array(); } 
        $index[$kname][] = $row["Column_name"]; 
    } 
    while (list($xy, $columns) = foreach($index[$kname])) { 
        $def .= ",\r\n"; 
        if ($xy == "PRIMARY") $def .= "PRIMARY KEY (".implode($columns, ", ").")"; 
        else if (substr($xy,0,6) == "UNIQUE") $def .= "    UNIQUE ".substr($xy,7)." (".implode($columns, ", ").")"; 
        else $def .= "    KEY $xy (".implode($columns, ", ").")"; 
    } 
    $def .= "\r\n);\r\n\r\n"; 
 
    $db = @mysql_select_db($database); 
    $table = "".$table; 
    $text = "#\r\n# Data for table `$table`\r\n#\r\n\r\n"; 
 
    $fd = fopen($file_name,"a+"); 
    fwrite($fd, $text.$def); 
    fclose($fd); 
 
    unset($data); 
    if ($table > "") { 
        $res0[] = @mysql_select_db($database); 
        $result = @mysql_query("SELECT * FROM $table"); 
        $anzahl = @mysql_num_rows($result); 
        $spaltenzahl = @mysql_num_fields($result); 
        for ($i = 0; $i < $anzahl; $i++) { 
            $zeile = @mysql_fetch_array($result); 
            $data .= "INSERT INTO $table ("; 
            for ($spalte = 0; $spalte < $spaltenzahl; $spalte++) { 
                $feldname = @mysql_field_name($result, $spalte); 
                if ($spalte == ($spaltenzahl - 1)) { 
                    $data.= $feldname; 
                } else { 
                    $data.= $feldname.","; 
                } 
            } 
            $data .= ") VALUES ("; 
            for ($k=0;$k < $spaltenzahl;$k++) { 
                if ($k == ($spaltenzahl - 1)) { 
                    $data .= "'".addslashes($zeile[$k])."'"; 
                } else { 
                    $data .= "'".addslashes($zeile[$k])."',"; 
            } 
            } 
            $data .= ");\r\n"; 
        } 
        $data .= "\r\n"; 
    } else { 
        $res0[] = "There is no table"; 
    } 
 
    $fd = fopen($file_name,"a+"); 
    fwrite($fd, $data); 
    fclose($fd); 
} 
 
$size0 = filesize($file_name) / 1024; 
 
 
echo"<hr>";
echo"Database name: <i>$db_name</i><br>";
echo"Number of tables: <i>".$counter."</i><br>";
echo"Size: <i>".number_format($size0,2)." KB</i><br>";
echo"<hr><br>";
 
echo "Thanks for a backup.<br>";
echo "The files were copied to the destination directory <b>YourAccount</b>/_Backups/<br>"; 
@mysql_close($connection); 
 
$counter = "";
$size0 = "";
?>
<center>[ <a href="?page=main"><?php echo $lang_back; ?></a> ]</font></center>
C'est censé sauvegarder les bases de données de mes utilisateurs dans leurs répertoires...MAIS, il me sort une erreur qui correspond à :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
while (list($xy, $columns) = foreach($index[$kname])) { 
        $def .= ",\r\n"; 
        if ($xy == "PRIMARY") $def .= "PRIMARY KEY (".implode($columns, ", ").")"; 
        else if (substr($xy,0,6) == "UNIQUE") $def .= "    UNIQUE ".substr($xy,7)." (".implode($columns, ", ").")"; 
        else $def .= "    KEY $xy (".implode($columns, ", ").")"; 
    } 
    $def .= "\r\n);\r\n\r\n";
Et je ne m'y connais pas assez en php pour savoir pourquoi le foreach merde

Car il me sort une erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
Parse error: syntax error, unexpected T_FOREACH in E:\services\zpanel\modules\mysql\backup.php on line 86
j'ai essayé de remettre le code suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
    while (list($xy, $columns) = each($index)) { 
        $def .= ",\r\n"; 
        if ($xy == "PRIMARY") $def .= "    PRIMARY KEY (".implode($columns, ", ").")"; 
        else if (substr($xy,0,6) == "UNIQUE") $def .= "    UNIQUE ".substr($xy,7)." (".implode($columns, ", ").")"; 
        else $def .= "    KEY $xy (".implode($columns, ", ").")"; 
    } 
    $def .= "\r\n);\r\n\r\n"; 
 
    $db = @mysql_select_db($database); 
    $table = "".$table; 
    $text = "#\r\n# Data for table `$table`\r\n#\r\n\r\n";

mais j'obtiens cette erreur :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Warning: Variable passed to each() is not an array or object in E:\services\zpanel\modules\mysql\backup.php on line 86
 
Warning: Variable passed to each() is not an array or object in E:\services\zpanel\modules\mysql\backup.php on line 86
 
Warning: Variable passed to each() is not an array or object in E:\services\zpanel\modules\mysql\backup.php on line 86
 
Warning: Variable passed to each() is not an array or object in E:\services\zpanel\modules\mysql\backup.php on line 86
 
Warning: Variable passed to each() is not an array or object in E:\services\zpanel\modules\mysql\backup.php on line 86
 
Warning: Variable passed to each() is not an array or object in E:\services\zpanel\modules\mysql\backup.php on line 86
 
Warning: Variable passed to each() is not an array or object in E:\services\zpanel\modules\mysql\backup.php on line 86
 
Warning: Variable passed to each() is not an array or object in E:\services\zpanel\modules\mysql\backup.php on line 86
 
Warning: Variable passed to each() is not an array or object in E:\services\zpanel\modules\mysql\backup.php on line 86
Merci d'avance de votre aide