title: Cannot query MySQL database via PHP
body: <p>In my PHP code, i'm easily writing records to my database but for some reason i can't read anythign out. My PHP code is:</p>
  
  <pre><code>$conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  } 
  
  $sql = "SELECT * FROM companies";
  
  if ($conn-&gt;query($sql) === TRUE)
  {
      echo "query success";
  
      while($row = $result-&gt;fetch_assoc())
      {
          echo "ID: " . $row["ID"]. " - Name: " . $row["name"]. "&lt;br&gt;";
      }
  }
  else
  {
      echo "query failure";
      echo "Error: " . $sql . "&lt;br&gt;" . $conn-&gt;error;
  }
  
  
  $sql = "INSERT INTO companies (name) 
          VALUES ('mycompany')";
  
  if ($conn-&gt;query($sql) === TRUE)
  {
  
      echo "insert success";
  }
  else
  {
      echo "insert failure";
      echo "Error: " . $sql . "&lt;br&gt;" . $conn-&gt;error;
  }
  </code></pre>
  
  <p>The output I get from the browser when i run it is:
  <code>query failureError: SELECT * FROM companies
  insert success</code></p>
  
  <p>I've tried variations of apostrophes, carets, quotes in that $sql string. I've tried running this query in HeidiSQL and it works fine. Any ideas where I'm going wrong? Any suggestions of more basic stuff I can try to narrow down the source of the problem?</p>
  
  <p>thanks!</p>