List:General Discussion« Previous MessageNext Message »
From:Chris Date:October 10 2006 1:19am
Subject:Re: What's the PHP equivallent of "mysql mydb < somefile.sql"
View as plain text  
Daevid Vincent wrote:
> Currently I run an 'updater' script to run through a directory of .sql files
> using something like this in PHP:
> 
> 	$COMMAND = "mysql ".$OPTION['db_prefix'].$db." < ".$mydir.$filename;
> 	system($COMMAND, $ret);
> 
> What would be the equivallent way to to this in a PHP mysql_query(""); way?
> 
> I see "LOAD", but that only works for data it seems.
> http://dev.mysql.com/doc/refman/5.0/en/load-data.html
> 
> These scripts I use have ALTER statements and CREATE and all other types of
> SQL in them and almost no data actually.

mysql_query can only run one statement at a time so you'd have to either:

- create a big array with the queries you want to run and run over them 
with a foreach loop.

- load up the sql file and explode on a character (eg newline or ; ) to 
get the separate queries

I'm sure there are other options but these are the two I regularly use.

-- 
Postgresql & php tutorials
http://www.designmagick.com/
Thread
What's the PHP equivallent of "mysql mydb < somefile.sql"Daevid Vincent10 Oct
Re: What's the PHP equivallent of "mysql mydb < somefile.sql"Chris10 Oct
RE: What's the PHP equivallent of "mysql mydb < somefile.sql"Ligaya A. Turmelle10 Oct
  • RE: What's the PHP equivallent of "mysql mydb < somefile.sql"Daevid Vincent10 Oct
    • Re: What's the PHP equivallent of "mysql mydb < somefile.sql"Chris W10 Oct