dsaff82024 2010-12-15 12:59
浏览 50
已采纳

通过php调用批处理文件备份mysql数据库

I failed with the mysqldump method earlier. Now I'm trying to just call the batch file which will call the mysqldump. The php file which calls the batch file, looks something like this:

<?php
shell_exec('c:\\abc.bat');

?>

And the batch file, which when I execute directly yields the 7kb sql file that I'm expecting:

mysqldump --opt -u root -ppassword onstor > c:\onstordb.sql

But when I use php to execute it, I get a 0 Kb file, I wonder why. I tried both shell_exec and exec. Is there something wrong with the parameters?

  • 写回答

1条回答 默认 最新

  • dsxay48646 2010-12-15 13:05
    关注

    http://www.php.net/manual/en/function.exec.php#85930

    It reads:

    I was having trouble using the PHP exec command to execute any batch file. Executing other commands (i.e., "dir") works fine). But if I executed a batch file, I receieved no output from the exec command.

    The server setup I have consists of Windows Server 2003 server running IIS6 and PHP 5.2.3. On this server, I have:

    1. Granted execute permissions to the Internet User on c:\windows\system32\cmd.exe.
    2. Granted Everyone->Full Control to the directory in which the batch file is written.
    3. Granted Everyone->Full Control on the entire c:\cygwin\bin directory and its contents.
    4. Granted the Internet User "log on as batch" permissions.
    5. Specified the full path to each file being executed.
    6. Tested these scripts running from the command line on the server and they work just fine.
    7. Ensured that %systemroot%\system32 is in the system path.

    It turns out that even with all of the above in place on the server, I had to specify the full path to cmd.exe in the exec call.

    When I used the call:

    $output = exec("c:\\windows\\system32\\cmd.exe /c $batchFileToRun");
    

    then everything worked fine. In my situation, $batchFileToRun was the actual system path to the batch file (i.e., the result of a call to realpath()).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了