I'm trying to import a Wordpress database via the command line, using PHP.
Yes, I know I can use the cPanel to do it via the phpMyAdmin (which is what I just did).
I would like to have a simple php file that I can import the database without having to log into cPanel, as I'm probably going to be doing this often for testing purposes on a production Wordpress blog for a customer.
What I have in the php file:
<?php system('mysql -h localhost -u MyUserName -p MyPassword -d MyDatabase < MyDumpFile;'); ?>
The only output I get is the same as if I entered 'mysql -?` from the command line.
I have verified that the username, password, database, and dump file names are all correct. When I changed it to a mysqldump command (with appropriate syntax changes), it worked fine.
I figure there is something I'm missing, but can't figure it out.
________
The 'system' command is one of the servers higher level functions known as a Shell script and is normally unavailable to users on shared hosting for security reasons. Note: some web hosting providers would of suspended your account if they found you trying to use this.
A workaround is to read the file to be imported to the database in large blocks and use the SQL Bulk Insert command syntax.