Roland
Roland

Reputation: 9731

SELECT INTO OUTFILE isn't working?

I keep trying to run this function and I have rewritten it in all ways possible, but I cannot get it work:

public function backup($location) {
    $database = 'logindb';

    $backup = $location.'/'.$database.'_backup_'.date('Y').'_'.date('m').'_'.date('d').'.sql';

    $sql = "SELECT * INTO OUTFILE '$backup' FROM users";

    if ($stmt = $this->connect->prepare($sql)){
        if ($stmt->execute()) {
            echo $stmt->error();    
        }
        $stmt->close();
        echo 'done';
    } else {
        echo 'Error';   
    }
}

What am I doing wrong or what could be wrong ?

Upvotes: 0

Views: 944

Answers (2)

makriria
makriria

Reputation: 383

Type ps-Af to see what is the username of your webserver (usually apache or httpd) Then type chown -R apache:apache (or httpd respactively) in one folder up your backup directory Then type chmod u+w I think that since webserver tries to write the file, it must have write permissions

Upvotes: 2

vimdude
vimdude

Reputation: 4595

mysql user must have write access to the path in $backup

Upvotes: 2

Related Questions