php mysql question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jzocco
Forum Newbie
Posts: 4
Joined: Mon Jun 13, 2005 11:35 am

php mysql question

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Jzocco
Forum Newbie
Posts: 4
Joined: Mon Jun 13, 2005 11:35 am

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Jzocco
Forum Newbie
Posts: 4
Joined: Mon Jun 13, 2005 11:35 am

Post by Jzocco »

thanks much appreciated
Post Reply