Jump to content

Making a database backup help


Imad

Recommended Posts

Hi guys, I'm trying to create this database backup script but it isn't working.  >:(

 

Here's the code:

 

// Database backup system
$settime = date(_mdys);
$namer = "$dbname$settime.txt";
$backupdoc = "inc/backup/$namer";

$query = "SELECT * INTO OUTFILE '$backupdoc' FROM comments";
if (mysql_query($query)) {
echo "<br />The Backup created successfully!";
}
else {
echo "<br />The Backup couldn't be created!"; }

 

Any help would be appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/96481-making-a-database-backup-help/
Share on other sites

Everything seems fine, but it still won't work.  I gave this a try:

$settime = date(_mdys);
$namer = "$dbname$settime.txt";
$backupdoc = fopen("inc/backup/$namer","w");

$query = "SELECT * INTO OUTFILE '$backupdoc' FROM users";
if (mysql_query($query)) {
echo "<br />The Backup created successfully!";
}
else {
echo "<br />The Backup couldn't be created!"; }

 

But it just creates a blank file as I expected. Any Ideas??

Regards.

this line:

$backupdoc = fopen("inc/backup/$namer","w");

 

fopen returns a file handler, not a string. and so when you passed what you thought was

a filename you passed to the mysql query a pointer ( internal).

try passing the full name of the output file to the query.

hth

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.