PHP MYSQL Carriage returns
<p>I have a script that is backing up a wordpress database, and it works great. However, I'm trying to restore it with php, and it always stops at the carriage returns, and errors out.
 Error:</p>

<blockquote>
  <p>\n\nThis is a text example, chang' at line 1</p>
  
  <p>You have an error in your SQL syntax; check the manual that
  corresponds to your MySQL server version for the right syntax to use
  near '\n\n</p>
</blockquote>

<p>I've tried <code>nl2br</code>, <code>htmlspecialchars</code>,  <code>mysql_real_escape_string</code>, even <code>preg-replacing</code> them. </p>

<p>here's the code I'm using:</p>

<pre><code>// Connect to MySQL server
mysql_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to MySQL server: ' . mysql_error());
// Select database
mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());

// Temporary variable, used to store current query
$templine = '';
// Read in entire file
$lines = file($filename, FILE_IGNORE_NEW_LINES);
// Loop through each line
foreach ($lines as $line)
{
    // Skip it if it's a comment
    if (substr($line, 0, 2) == '--' || $line == '')
        continue;

    // Add this line to the current segment
    $templine .= $line;
    // If it has a semicolon at the end, it's the end of the query
    if (substr(trim($line), -1, 1) == ';')
    {
        // Perform the query
        mysql_query($templine) or print(mysql_error() . '&lt;br /&gt;&lt;br /&gt;');
        // Reset temp variable to empty
        $templine = '';
       }
}
</code></pre>

<p>the <code>$filename</code> variable is an <code>.sql</code> file that is formatted correctly. In the database dump, I can see the <strong>\n's</strong>, and I'm pretty sure <code>wordpress</code> does some sort of <code>nl2br</code>, and replaces them with <code>&lt;p&gt;</code>'s, so they can be removed or the spacing on the site gets removed completely.</p>
