I'm trying to dump a table into a MySQL file using PHP. But what I get is an empty array, and not any file is created. While if I remove the instruction " INTO OUTFILE '$mysqldumpfile'", everything works fine. please here the code:
<?php
$tablename = "song";
$mysqldumpfile = "mysql_dump.sql";
$pdo_options = array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', );
try {
// Call MySQL DB
$sql = new PDO($servername, $username, $password, $pdo_options);
} catch (PDOException $e) {
die("DB not available");
}
// Dump MySQL
$sth = $sql->prepare("SELECT * INTO OUTFILE '$mysqldumpfile' FROM $tablename");
$sth->execute();
$result = $sth->fetchAll();
print_r($result);
if(! $result) {
die('Could not load data : ' . mysql_error());
}
$sql = null;
?>