Database PHP Programming

PHP: Importing an SQL file via PHP script

Trying to import an SQL file using PHP? Most people will tell you that using PHP function shell_exec to run the MySQL client is your best bet, but what if you simply can’t do it that way? The solution is quite simple, actually, and doesn’t require programming skills beyond the basic file parsing and query executing.

Importing SQL Files

The following function assumes you already have an SQL connection open, and you’re using the MySQLi extension (which you should be using over the MySQL extension, but that’s discussion for another day).

Here you go:

Leave a Reply

Your email address will not be published. Required fields are marked *