What are potential limitations or syntax issues when using "select into outfile" in MySQL for exporting data to a CSV file?

When using "select into outfile" in MySQL to export data to a CSV file, potential limitations or syntax issues may arise if the file path is not specified correctly or if the user running the MySQL server does not have the necessary permissions to write to the specified directory. To solve this issue, ensure that the file path is valid and that the MySQL user has the appropriate permissions to write to the directory.

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * INTO OUTFILE '/path/to/output.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' FROM table_name";
$result = $conn->query($sql);

if (!$result) {
    die("Export failed: " . $conn->error);
}

echo "Data exported successfully to /path/to/output.csv";

$conn->close();
?>