コード例 #1
0
ファイル: admin.php プロジェクト: kurt-planet/BigTree-CMS
 static function backupDatabase($file)
 {
     if (!BigTree::isDirectoryWritable($file)) {
         return false;
     }
     $pointer = fopen($file, "w");
     fwrite($pointer, "SET SESSION sql_mode = 'NO_AUTO_VALUE_ON_ZERO';\n");
     fwrite($pointer, "SET foreign_key_checks = 0;\n\n");
     // We need to dump the bigtree tables in the proper order or they will not properly be recreated with the right foreign keys
     $q = sqlquery("SHOW TABLES");
     while ($f = sqlfetch($q)) {
         $table = current($f);
         // Write the drop / create statements
         fwrite($pointer, "DROP TABLE IF EXISTS `{$table}`;\n");
         $definition = sqlfetch(sqlquery("SHOW CREATE TABLE `{$table}`"));
         fwrite($pointer, str_replace(array("\n  ", "\n"), "", end($definition)) . ";\n");
         // Get all the table contents, write them out
         $rows = BigTree::tableContents($table);
         foreach ($rows as $row) {
             fwrite($pointer, $row . ";\n");
         }
         // Separate it from the next table
         fwrite($pointer, "\n");
     }
     fwrite($pointer, "\nSET foreign_key_checks = 1;");
     fclose($pointer);
     return true;
 }