title: How do I import a .sql file in mysql database using PHP?
body: <p>I'm trying to import a .sql file through PHP code. However, my code shows this error:</p>
  
  <pre><code>There was an error during import. Please make sure the import file is saved in the same folder as this script and check your values:
  
  MySQL Database Name:    test
  MySQL User Name:    root
  MySQL Password: NOTSHOWN
  MySQL Host Name:    localhost
  MySQL Import Filename:  dbbackupmember.sql
  </code></pre>
  
  <p>And this is my code:</p>
  
  <pre><code>&lt;?php
  //ENTER THE RELEVANT INFO BELOW
  $mysqlDatabaseName ='test';
  $mysqlUserName ='root';
  $mysqlPassword ='';
  $mysqlHostName ='localhost';
  $mysqlImportFilename ='dbbackupmember.sql';
  //DONT EDIT BELOW THIS LINE
  //Export the database and output the status to the page
  $command='mysql -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' &lt; ' .$mysqlImportFilename;
  exec($command,$output=array(),$worked);
  switch($worked){
      case 0:
          echo 'Import file &lt;b&gt;' .$mysqlImportFilename .'&lt;/b&gt; successfully imported to database &lt;b&gt;' .$mysqlDatabaseName .'&lt;/b&gt;';
          break;
      case 1:
          echo 'There was an error during import. Please make sure the import file is saved in the same folder as this script and check your values:&lt;br/&gt;&lt;br/&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;MySQL Database Name:&lt;/td&gt;&lt;td&gt;&lt;b&gt;' .$mysqlDatabaseName .'&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;MySQL User Name:&lt;/td&gt;&lt;td&gt;&lt;b&gt;' .$mysqlUserName .'&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;MySQL Password:&lt;/td&gt;&lt;td&gt;&lt;b&gt;NOTSHOWN&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;MySQL Host Name:&lt;/td&gt;&lt;td&gt;&lt;b&gt;' .$mysqlHostName .'&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;MySQL Import Filename:&lt;/td&gt;&lt;td&gt;&lt;b&gt;' .$mysqlImportFilename .'&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;';
          break;
  }
  ?&gt;
  </code></pre>
  
  <p>What am I doing wrong? The SQL file is in the same directory.</p>