Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Database configuration
- $host = "localhost";
- $username = "mobstersonline_owner";
- $password = "Enterprise89";
- $database_name = "mobstersonline_mobstersonline";
- // Get connection object and set the charset
- $conn = mysqli_connect($host, $username, $password, $database_name);
- $conn->set_charset("utf8");
- // Get All Table Names From the Database
- $tables = array();
- $sql = "SHOW TABLES";
- $result = mysqli_query($conn, $sql);
- while ($row = mysqli_fetch_row($result)) {
- $tables[] = $row[0];
- }
- $result = mysqli_query($conn, $sql);
- while ($row = mysqli_fetch_row($result)) {
- $tables[] = $row[0];
- }
- ?>
- <?php
- $sqlScript = "";
- foreach ($tables as $table) {
- // Prepare SQLscript for creating table structure
- $query = "SHOW CREATE TABLE $table";
- $result = mysqli_query($conn, $query);
- $row = mysqli_fetch_row($result);
- $sqlScript .= "\n\n" . $row[1] . ";\n\n";
- $query = "SELECT * FROM $table";
- $result = mysqli_query($conn, $query);
- $columnCount = mysqli_num_fields($result);
- // Prepare SQLscript for dumping data for each table
- for ($i = 0; $i < $columnCount; $i ++) {
- while ($row = mysqli_fetch_row($result)) {
- $sqlScript .= "INSERT INTO $table VALUES(";
- for ($j = 0; $j < $columnCount; $j ++) {
- $row[$j] = $row[$j];
- if (isset($row[$j])) {
- $sqlScript .= '"' . $row[$j] . '"';
- } else {
- $sqlScript .= '""';
- }
- if ($j < ($columnCount - 1)) {
- $sqlScript .= ',';
- }
- }
- $sqlScript .= ");\n";
- }
- }
- $sqlScript .= "\n";
- }
- ?>
- <?php
- if(!empty($sqlScript))
- {
- // Save the SQL script to a backup file
- $backup_file_name = $database_name . '_backup_' . time() . '.sql';
- $fileHandler = fopen($backup_file_name, 'w+');
- $number_of_lines = fwrite($fileHandler, $sqlScript);
- fclose($fileHandler);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement