Forum Moderators: coopster

Message Too Old, No Replies

How can I load a mysqldump with PHP

         

smithaa02

3:29 pm on Dec 22, 2006 (gmt 0)

10+ Year Member



Basically, I have a mysql dump with table creates and data inserts all in a giant text file. What I want to do is to put all those tables into a specified database using PHP. My questions is what is the best way to this? mysql_query() can only do one command at a time.

mcavic

4:17 pm on Dec 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The only easy way I know of is to use system() or popen() to shell out to mysql and tell it to select a database, and run the dump file. But, you have to tell mysql your password in a secure way.

jatar_k

4:26 pm on Dec 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I always do it from the command line using something like

mysql -u username -p < dump/file/path/filename.sql

you may need to add the host or database name to that command as well

as mcavic says you could run that command using system, passthru or exec