PHP: load SQL lines

first of all I want to give a big applause to Tobias Ratschiller, the creator
of ! His nice tool phpMyAdmin helped me a lot administrating my mySQL-database. phpMyAdmin is probably the best
script around!! Often I was looking at his code to get some ideas and solve my
The following snippet has been taken out of his code. I just changed a couple
of things to let it run as an independent function.

You can write a whole bunch of lines of SQL in a text-file and then just call
up the function to load it all into your database.
It parses through your file and executes every single query. To add comments in
your file, please use #
If you provide the function with its optional attributes old_string and new_string
it’s going to do a search-replace on your file before entering it into your database.
I used this to add user-accounts to my free-counter. Like this I can use one single
file as a pattern for all user tables. In my file I’m just replacing xxxxx to
the correct user-id.
all credits of this snippet go to Tobias Ratschiller!

here’s my function definition:

boolean exec_sql_lines(string sql_file, [string old_string], [string new_string])

Comments are closed