title: Restoring a MySQL database in PHP via client upload (.sql file)
body: <p>Alright, so I've successfully been able to take a database created in PHPMyAdmin, and back it up to the client with php; now I'm trying to restore that database as a new database within the same environment. </p>
  
  <p>I've found the command that works within mysql, but I can't seem to get it to work with a file that the client uploads from their computer. </p>
  
  <p>Here is the code I have right now: </p>
  
  <pre><code>&lt;?php
      // display form if user has not clicked submit
      if (!isset($_POST["btn_submit"])) 
      {
  ?&gt;
  
  &lt;!--This will be the form that will hold the information of the entire page.--&gt;
  &lt;form enctype="multipart/form-data"class="elegant-aero" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
      &lt;h1&gt;Restore Database&lt;/h1&gt;
      &lt;p&gt;
          &lt;label&gt;
              &lt;span&gt;Database File&lt;/span&gt;
              &lt;input type="file" name="backupFile" value="Upload File"&gt;
          &lt;/label&gt;
  
          &lt;!--Submit Button--&gt;
          &lt;label&gt;
              &lt;span&gt;&amp;nbsp;&lt;/span&gt;
              &lt;input type="submit" name="btn_submit" class="button" value="Add Scenario"/&gt;
          &lt;/label&gt;
      &lt;/p&gt;
  &lt;/form&gt;
  
  &lt;?php
  
      } //end if
  
      else 
      {
          if(isset($_FILES['backupFile']['error']) &amp;&amp; UPLOAD_ERR_OK == $_FILES['backupFile']['error'])
          {
              //Format sql file
              $file = addslashes(file_get_contents($_FILES['backupFile']['tmp_name']));
          } //end if
  
          //Set up the MySQL Server
          $servername = "localhost";
          $username = "root";
          $password = "password";//hide your password
          $dbname = "test";
  
          //Create connection to the MySQL server
          $conn = new mysqli($servername, $username, $password);
  
          $sql1 = "CREATE DATABASE test"; 
  
          if($conn-&gt;query($sql1) === TRUE) 
          {
              echo "Database created successfully&lt;br&gt;"; 
          } else {
              echo "Error creating database: " . $conn-&gt;error; 
          } //end else
  
          $sql2 = "mysql --user={$username} --password={$password} --database={$dbname} &lt; $file";
  
          if($conn-&gt;query($sql2) === TRUE) 
          {
              echo "Information uploaded successfully&lt;br&gt;"; 
          } else {
              echo "Error uploading information: " . $conn-&gt;error; 
          } //end else
  
      } //end else
  
  ?&gt;
  </code></pre>