Backup of table

Here’s My Code to create backup of a table

<?php
		include 'connection.php';
		 $table_name = "brand";
                 $backup_file  = "D:/wamp64/www/ShoppingTemplate/backup/employee15.sql";
                 echo $sql = "SELECT * INTO OUTFILE '$backup_file'  FROM $table_name";
	 mysqli_query($con,$sql);
   if(! $sql ) {
      die('Could not load data : '.mysqli_error($con));
   }
   echo "Loaded  data successfully\n";
?>

This create a new backup copy of table.But after updating a table and again taking the backup, The same backup file is not updating at all.
Do I need to create new file whenever the backup is taken?

According to the MySQL documentation:

“The SELECT … INTO OUTFILE ‘file_name’ form of SELECT writes the selected rows to a file. The file is created on the server host, so you must have the FILE privilege to use this syntax. file_name cannot be an existing file, which among other things prevents files such as /etc/passwd and database tables from being destroyed. The character_set_filesystem system variable controls the interpretation of the file name.”

http://dev.mysql.com/doc/refman/5.7/en/select-into.html

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.