简体   繁体   中英

Laravel mysqldump create empty file, but same command work when execute via xampp shell

running Laravel 5.2 on Xampp 321 Win7 Mysql5.6 PHP 5.6.3 I cant create BD dump file .sql

        $filename = "backup-".Carbon\Carbon::now()->format('Y-m-d_H-i-s').".sql  2>&1";

        try{
          $command = "mysqldump --user=" . env('DB_USERNAME') ." --password=" . env('DB_PASSWORD') . " --host=" . env('DB_HOST') . " " . env('DB_DATABASE') . "  > " . storage_path() . "/" . $filename;
          $returnVar = NULL;
          $output  = NULL;
          //exec command allows you to run terminal commands from php 
          exec($command, $output, $returnVar);
          //dd($command);  
          return 1;    
         }catch(Exception $e){
           return $e->errorInfo; //some error
         }

When loading script it generates an empty file! But by doing dd ($ command) and copying paste this text, this command works fine in the Xampp shell. Any ideas please?

Solved with this code: setting absolute path of mysqldump adn adding double backslash to url var

    $filename = "backup-".date("d-m-Y-H-i-s").".sql";
    $mysqlPath = "D:\\xampp/mysql/bin/mysqldump";

    try{
        $command = "$mysqlPath --user=" . env('DB_USERNAME') ." --password=" . env('DB_PASSWORD') . " --host=" . env('DB_HOST') . " " . env('DB_DATABASE') . "  > " . storage_path() . "/" . $filename."  2>&1";
        $returnVar = NULL;
        $output  = NULL;
        exec($command, $output, $returnVar);
        return 1;//ok

     }catch(Exception $e){
        return "0 ".$e->errorInfo; //some error
     }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM