I have this code that I found but I have a problem trying to get it to work... It says that there is no file and directory, what does that mean and how can I fix it? Also how do I adapt the code to backup the whole database and not just the table:
<?php
$servername = ""; //this is the local server name
$username = ""; // this is mysql username for my database
$password = ""; // this is the database password
$database = ""; //this is the database name
$conn = new mysqli($servername, $username, $password, $database); //this will create a connection to the database
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$table_name = "activities";
$backup_file = "/tmp/activities.sql";
$sql = "SELECT * INTO OUTFILE '$backup_file' FROM $table_name";
mysql_select_db('');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not take data backup: ' . mysql_error());
}
echo "Backedup data successfully\n";
mysql_close($conn);
?>
Updated code:
$conn = new mysqli($servername, $username, $password, $database); //this will create a connection to the database
if(! $conn ) {
die('Could not connect: ' . mysqli_error());
}
$table_name = "activities";
$backup_file = "/tmp/activities.sql";
$sql = "SELECT * INTO OUTFILE '$backup_file' FROM $table_name";
mysqli_select_db('');
$retval = mysqli_query( $sql, $conn );
if(! $retval ) {
die('Could not take data backup: ' . mysqli_error());
}
echo "Backedup data successfully\n";
mysqli_close($conn);
?>