0

I want to transfer data from test server database to live server database. The data is in the form of a .sql file. So using php on stage server can I transfer the data using shell_exec();

$command = "mysql -u{$vals['db_user']} -p{$vals['db_pass']} "
 . "-h {$vals['db_host']} -D {$vals['db_name']} < {$script_path}";

$output = shell_exec($command . '/shellexec.sql');

The above code is not working. is there any other way?

provokoe
  • 178
  • 2
  • 10
  • Why do you need to do it via PHP? Can't you use the command line? – Aydin Hassan Apr 04 '13 at 09:22
  • I would suggest you write a bash script that does the actual import and you execute that with PHP. – cen Apr 04 '13 at 09:22
  • You could connect to the DB in PHP, do a file_get_contents and then execute it via mysql_query. Example: http://stackoverflow.com/a/6607547/1337431 – Diogo Raminhos Apr 04 '13 at 09:23
  • @Whiteagle but the live db is in different Server. – provokoe Apr 04 '13 at 09:24
  • 1
    @Partha, you can connect to a remote MySQL server (you do not need to connect to your local server, you can connect to a remote host without any problem :]), you'll just need to open the MySQL ports on the firewall and allow the user access from that specific IP Address. – Diogo Raminhos Apr 04 '13 at 09:26
  • 'Not working' isn't very helpful, do you not have an error message to share? – piddl0r Apr 04 '13 at 09:48

0 Answers0