title: Best practice to execute multiple SQL queries using PHP PDO
body: <p>What is the best practice to execute multiple SQL queries using PHP PDO?</p>
  
  <p>I have 4 tables and each of them is running on MyISAM. As such they do not have Foreign Key support. It's a one-to-many design whereby there is 1 main table and the other table contains reference to the main table in the form of IDs.</p>
  
  <p>For now, what I do is that I run the first query to get the ID from the main table. Once that is executed, I then perform another query to query other tables using the ID from the first query. Results from both the queries are then merged together (array_merge) and then displayed to the user.</p>
  
  <p>Here's my code so far. I think you will get the gist and you can most probably tell that I'm a super beginner in PHP. :)</p>
  
  <pre><code>$sql1 = "SELECT * FROM student_records WHERE name=? LIMIT 1";
  $stmt1 = $db-&gt;prepare($sql1);
  $stmt1-&gt;execute(array($name));
  $e11 = $stmt1-&gt;fetch();
  
  $id = $e1['id'];
  
  $sql2 = "SELECT file_name FROM images WHERE id=? LIMIT 1";
  $stmt2 = $db-&gt;prepare($sql2);
  $stmt2-&gt;execute(array($id));
  $e2 = $stmt2-&gt;fetch();
  
  $e = array_merge($e1, $e2);
  </code></pre>
  
  <p>I think that the code above is somewhat repetitive and redundant. Is there any suggestion and tips on how I can improve this?</p>