I want to create a form in PHP that will load a .sql file, read its contents, and execute those statements against a MySQL database.
Currently using function get_file_contents
but it's not working. What can I do?
I want to create a form in PHP that will load a .sql file, read its contents, and execute those statements against a MySQL database.
Currently using function get_file_contents
but it's not working. What can I do?
If you have several queries in your file, you'll either have to :
mysql_query
or mysqli_query
for each one of those queries.
mysql_query
: "multiple queries are not supported"mysqli_multi_query
to send several queries at once
mysql_*
family of functionsmysql
command-line client, to import the file, with something like this (you'll have to pass the right values, of course) :
mysql --user=USERNAME --password=PASSWORD --host=localhost DATABASENAME < your-file.sql