can i execute a SQL file with PHP?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Guest
I know that i can execute a SQL sentence for a MySQL database, but i dont know if i can execute an entire *.sql file.

Can anybody help me and said me how?

Thanks!!
 
You can't execute a file as it stands, but you can read the file, split it down into the appropriate sentences and execute them individually.
 
you can take a look at phpmyadmin, because it is possible to execute the query's in an sql-file with phpmyadmin.
So you can take a look at how they did it.

Greetz Daan
 
dvdbinternet said:
you can take a look at phpmyadmin, because it is possible to execute the query's in an sql-file with phpmyadmin.
So you can take a look at how they did it.

Greetz Daan
I already deciphered it, they spilt the query up into single commands and execute them individually.

You'll notice once you execute a file in PHPMyAdmin it'll tell you how many commands were executed.
 
For instance, sql script is "script.sql."
U can use:

exec('mysql < script.sql') in local variant

or specify command line parameters (for help: 'mysql --h') - sever, username, password, etc in case of remote mysql server.

------------------------
With best regards,
Serge Bulanov
AlarIT Web developer,
http://www.AlarIT.com
 
Back
Top