0

I am looking for a good php script that will create a backup of a few tables.

However the method I want to use is, to create txt files that contain delete, reseed and insert statements to re-insert the backed up data.

I already have seen how in SSMS, can generate scripts to do the same thing.

But want an example of one in php.

So i can run this as a cron/scheduled task, to create txt files full of sql i can use safely to rollback data...WHich I think is a far easier to manage solution, then the normal sql server backup process.

Thank you.

crosenblum
  • 1,869
  • 5
  • 34
  • 57
  • Actually this is sql server, and i am not dumping the whole database, just creating insert statements in php to repopulate a few tables. – crosenblum Aug 12 '12 at 20:06
  • Just to clarify, this is to be an php equivalent to SSMS generating scripts to backup a table. Only I want to do it in PHP. Generate strings that hold all needed sql commands. – crosenblum Aug 12 '12 at 20:08
  • This script will take all the data, does not regenerate the tables themselves, and then re-inserts the current data, after erasing existing data. – crosenblum Aug 12 '12 at 20:09
  • Dagon, your answer is not a good match, since my solution has to be a php script. Yes of course there are wonderful software out there, but that's not the need I have. With a php script I can schedule it, and would take up less resources than using a piece of software. – crosenblum Aug 13 '12 at 02:14
  • Any other answers? I want to basically create a text file that has this week's current data in it. And as port of the restore process, delete's current data, reseed's table, then inserts the old data back in. To make for easier restore/backups for my game server database. – crosenblum Sep 07 '12 at 21:25

1 Answers1

0
$disk = "E:\\TestBackup\\Test.bak";
$backupQuery = "USE [dbName]  \n  BACKUP DATABASE [dbName] TO DISK = '$disk' ";
$backupResult = sqlsrv_query($conn,$backupQuery) or die(print_r(sqlsrv_errors()));
David Buck
  • 3,752
  • 35
  • 31
  • 35