Page 1 of 1

how can I import a .sql file with PHP

Posted: Tue Apr 07, 2009 12:22 pm
by Leb_CRX
I can't seem to find this, I've tried searching and so far, nothing

I have a MySQL dump file being transferred between servers, on the new server I want to run a script that imports it into a MySQL...it can't be done using a prompt, since permissions don't allow it

is there anything built into PHP that can do this? I've tried writing a few scripts and keep coming close, but nothing seems to be working

Re: how can I import a .sql file with PHP

Posted: Tue Apr 07, 2009 12:57 pm
by Christopher
Is it an SQL or CSV file? If it is SQL then open, read it and run the queries. If it is CSV then use "LOAD DATA INFILE".

Re: how can I import a .sql file with PHP

Posted: Tue Apr 07, 2009 10:41 pm
by Leb_CRX
arborint wrote:Is it an SQL or CSV file? If it is SQL then open, read it and run the queries. If it is CSV then use "LOAD DATA INFILE".
it's an SQL

I finally found a script, and it is:

Code: Select all

        $sql = explode(';', file_get_contents('healthm.sql'));
        foreach ($sql as $key => $val) {
            mysql_query($val);
        }
I overcomplicated it...it was my bad