This is a discussion on Re: Import .sql file into MySQL DB ? within the PHP Language forums, part of the PHP Programming Forums category; Jerry T <Jerry@ nothanks.com> wrote in message news:<drgkjv03hrpc69p2tt5v0pjmfdspqlnesf@4ax.com>. .. > > Using a ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Jerry T <Jerry@ nothanks.com> wrote in message
news:<drgkjv03hrpc69p2tt5v0pjmfdspqlnesf@4ax.com>. .. > > Using a script I found, I can get data out of my MySQL DB, > but how do I get it back in ... phpMyAdmin has a functionality to execute *.sql files. > the .sql file is like this : > > DROP TABLE IF EXISTS columns_priv;#%% > CREATE TABLE columns_priv ( > Host char(60) binary NOT NULL, > Db char(64) binary NOT NULL, > User char(16) binary NOT NULL, > Table_name char(64) binary NOT NULL, > Column_name char(64) binary NOT NULL, > Timestamp timestamp(14), > Column_priv set('Select','Insert','Update','References') NOT NULL, > PRIMARY KEY (Host, Db, User, Table_name, Column_name) > );#%% [the rest of the file skipped] You can try somthing like this: // let's pretend that connection to server is established // and database chosen... $sql = explode(';#%%', file_get_contents ('backup.sql')); $n = count ($sql) - 1; for ($i = 0; $i < $n, $i++) { $query = $sql[$i]; $result = mysql_query ($query) or die ('<p>Query: <br><tt>' . $query . '</tt><br>failed. MySQL error: ' . mysql_error()); } Note that I am using ';#%%' to break the file into queries simply because your backupo script seems to insert it after each query. Normally, queries would end with ';' alone. Also note that the for() cycle is written so that the last member of the $sql array is not executed, since that member does not contain any SQL (there can be no SQL after the last occurrence of ';'). Cheers, NC |