当然可以生成一个转储文件,然后读取这个文件并放入一个变量中。但是有没有办法检索转储并直接放入变量中?谢谢!
2 回答
you can run it with shell_exec.
then all output is put in the php variable.
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.
您可以使用 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/manual/en/function.exec.php
http://pl1.php.net/manual/en/function.shell-exec.php
mysqldump 是一个应该在您的 BIN 目录中的程序。