0

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?

6
  • Are you using artisan command? Commented Feb 7, 2017 at 23:37
  • no, cmd directly (from shell of xampp panel) Commented Feb 7, 2017 at 23:57
  • How do you intend to run it from Laravel? If you want it to run from Laravel, follow instructions here: laravel.com/docs/5.2/artisan Commented Feb 8, 2017 at 0:00
  • I would like to execute the task with pure php from a Laravel controller, calling a command to the mysql engine directly, I would like to know if it is possible and why write a .sql file empty 0KB Commented Feb 8, 2017 at 0:13
  • Yes, you can call artisan commands from controllers. laravel.com/docs/5.2/artisan#calling-commands-via-code Commented Feb 8, 2017 at 0:38

1 Answer 1

1

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
     }
Sign up to request clarification or add additional context in comments.

1 Comment

Problem solved by adding SQL dump absolute path. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.