I have a php calling sqlserver backup script. The script, if executed directly from SSMS, it created the backups successfully. But, when called via php, I can see the file created on the destination folder, but it seems that when php finishes, the file also got deleted. Where do I do wrong here?
PHP:
$strSQL = file_get_contents("archdata.sql");
if (!empty($strSQL)) {
$query=$conn->prepare($strSQL);
if ($query->execute()) {
sleep(5);
echo "1";
} else {
echo "Error: " . $strSQL;
}
}
archdata.sql:
SET @path = 'C:\Data\backups\'
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)
SET @fileName = @path + 'ProdDB _' + @fileDate + '.BAK'
BACKUP DATABASE ProdDB TO DISK=@fileName WITH STATS = 1