Page 1 of 1

php mysql question

Posted: Mon Jun 13, 2005 11:41 am
by Jzocco
i am fairly new to php but i have mysql down to an art and i would like to create a php page that restores my database im kinda curious how to get this thing rolling. If anyone has any ideas i would greatly appreciate them.

thanks

Posted: Mon Jun 13, 2005 11:56 am
by pickle
Do you mean restoring your database from a mysqldump file? As far as I know, PHP doesn't have anything built in that deals with mysqldump or restoring from files. However, you can use PHP to call shell commands, which could restore just fine.

Posted: Mon Jun 13, 2005 12:01 pm
by Jzocco
yes thats what im looking for im just not sure how to make that work i have like no php skills at all

Posted: Mon Jun 13, 2005 12:07 pm
by pickle
PHP has 3 different ways to call shell commands. shell_exec() and the backtick operator (`) are analogous, return the output from the command, and are disabled in safe mode. exec() just executes the command and may or may not be disabled in safe mode (couldn't find any info either way)

Code: Select all

$return_value = shell_exec('mysql -u root -proot_password test_database < dump_file.sql');
...should be what you're looking for.

Posted: Mon Jun 13, 2005 12:39 pm
by Jzocco
thanks much appreciated