0

当然可以生成一个转储文件,然后读取这个文件并放入一个变量中。但是有没有办法检索转储并直接放入变量中?谢谢!

4

2 回答 2

0

you can run it with shell_exec.

then all output is put in the php variable.

http://nl3.php.net/shell_exec

Edit, but please note that the output buffer for shell_exec is not unlimited. So if the DB grows very large, you will reach a moment where it will simply not function anymore. Also putting this in a variable puts it in memory. This might take up a lot of memory if you have a large DB.

I would advise to write it to a file and throughput it directly to the output when needed in php.

于 2013-04-29T09:35:15.650 回答
0

您可以使用 shell_exec() 或 exec() 但将所有输出都放到变量中是个坏主意。

exec('mysqldump --user=your_user --password=your_pass --host=your_host DATABASENAME > /path/dump.sql');

您可以使用 exec 并在完成工作后使用 file_get_contents() 打开文件

更多关于:

http://pl1.php.net/exec

http://pl1.php.net/manual/en/function.exec.php

http://pl1.php.net/manual/en/function.shell-exec.php

mysqldump 是一个应该在您的 BIN 目录中的程序。

于 2013-04-29T09:51:20.880 回答