0

First of I searched all around and could not find a valid answer.

I want to import database files into a database using PHP.

The following only works if the import.php file resides in the same folder (temp) as the database files:

$command = "gunzip --to-stdout $backupfile | mysql -u$database_user -p$database_pass $database";

If I place the import.php in another location and add a path to the $backupfile, it does not work as shown below:

$database_path = '/home/site/public_html/temp/';
$command = "gunzip --to-stdout $database_path.$backupfile | mysql -u$database_user -p$database_pass $database";

What is the correct way to add the path to the database file ($backupfile) so that I can run the PHP script from any location?

Thanks in advance.

4

2 回答 2

1

Try this :

$command = "gunzip --to-stdout {$database_path}{$backupfile} | mysql -u$database_user -p$database_pass $database";
于 2013-11-10T20:37:04.530 回答
0

I'd go with:

$database_path = '/home/site/public_html/temp/';
$command = 'gunzip --to-stdout ' . $database_path . $backupfile . ' | mysql -u' . $database_user . ' -p' . $database_pass . ' ' . $database;

or first execute command $c2 = 'cd ' . $database_path;

于 2013-11-10T20:37:50.960 回答