Search code examples
phpsqllaravelslash

Laravel SELECT INTO OUTFILE: writing to file error


I am trying to backup my database using the select into outfile statement in the Laravel 4. this is my code

$file = storage_path('db.sql');
DB::statement("SELECT * INTO OUTFILE '".$file."' FROM profiles");

But I receive the following error:

..Can not create/write to ..laravelappstorage\db.sql

Actually it strips the slashes in the file path,

what is the solution?


Solution

  • As Ademir Nuno mentioned I need to double the slashes

    DB::statement("SELECT * INTO OUTFILE '".addslashes($file)."' FROM profiles");
    

    and have user permissions