Forum Moderators: coopster

Message Too Old, No Replies

Using Exec Function to Dump Dump Database

To restore databases

         

naitsirhc26

8:09 am on Jan 10, 2008 (gmt 0)

10+ Year Member



Hello,

Right now I am working out how to use the Exec function to call upon a .txt file to dump into a database. Following is my little php script, and I was wondering if my syntax is correct thus far. I don't want to make any mistakes, as I know that could ultimately hurt my database. Though I always keep a backup. :-)

<?php

exec('mysql -u usernamegoeshere --password="yourpassword" -h localhost databasenamegoeshere < .http://www.urltoyourtextfilegoeshere.com/widget.txt', $response);

?>

Thank you in advance for any help or insights.

naitsirhc26

coopster

5:22 pm on Jan 10, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I've never streamed to STDIN from an external HTTP URL so I'm not certain of the syntax. However, I'm not so certain I would want to without scrubbing it first. Think of the security issues here. How about allowing the user to upload their text file and then you process it from there using MySQL rather than the OS shell? I think that route would be a much safer design.

PHP_Chimp

5:49 pm on Jan 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why are you calling the exec function?
I would suggest either doing it the usual mysql_connect/query way, or if you want to run it from the command line then do that. You could always set up a cronjob to run at regular intervals.

As you are just asking for someone to put 'rm -rf /' in there...and that wont just make a mess of your database. Actually it wont make a mess of a lot...as there wont be a lot left.