Created
November 6, 2017 08:08
-
-
Save hussnainsheikh/6b94c574562b39e166f61f4d1ae4574e to your computer and use it in GitHub Desktop.
Back up database tables.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dbhost = 'DB_Host'; // Database Host | |
$dbuser = 'DB_User'; // Database User | |
$dbpass = 'DBUser_Password'; // Database User Password | |
$db='DB_Name'; // Database Name | |
$i=0; | |
$conn = mysql_connect($dbhost, $dbuser, $dbpass); | |
mysql_select_db($db); | |
if(! $conn ) { | |
die('Could not connect: ' . mysql_error()); | |
} | |
$sql= "SHOW TABLES from $db"; | |
$result = mysql_query( $sql, $conn ); | |
while ($row=mysql_fetch_array($result)) { | |
echo $table_name= $row[0]; | |
echo "</br>"; | |
$i++; | |
$backup_file = getcwd() .$table_name .'.sql'; | |
$sql1 = "SELECT * INTO OUTFILE '$backup_file' FROM $table_name"; | |
$retval = mysql_query( $sql1, $conn ); | |
if(! $retval ) { | |
die('Could not take data backup: ' . mysql_error()); | |
} | |
echo "Eport " . $table_name . " Successfully</br>"; | |
} | |
echo "Number of tables: " . $i . "</br>"; | |
mysql_close($conn); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment