Forum Moderators: coopster

Message Too Old, No Replies

Restore Database Using PHP

         

eelixduppy

10:44 pm on Jun 19, 2006 (gmt 0)



Hello everyone.

I'm just posting this problem I have to get some suggestions. I created an install file for a client (sort of like phpBB's install file) that creates everything that is needed for the site. However, I have information in the database that I want to restore once everything is created on their server. The backup was created using mysqldump, but I cannot figure out how to load that backup into their server when I do not know the location of mysql.exe (this is the only way I know how to restore). I think the solution might involve using the source mysql command, but I cannot get it :(

Any suggestions are greatly appreciated. Thanks!

jatar_k

10:55 pm on Jun 19, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



take a look at the dumped file, usually they are just a load of commands

open file
read line
send to mysql
next

close and unlink (if necessary) once all commands have been completed

eelixduppy

11:41 pm on Jun 19, 2006 (gmt 0)



Thanks for putting me on the right path ;) I got it, but edited the dumped file a little bit so that the script knew where each query was, especially since the info contained "\n"'s . I added ##END## to the end of each query and used this script; it works fine for what I need

$text = file_get_contents("backup.sql");
$inserts = explode("##END##",$text);
$count = count($inserts);
for($i = 0; $i<$count; $i++)
{
mysql_query($inserts[$i]);
}

Thanks again jatar ;)