title: Using a mySQL Prepared Statement in Multiple Class Instances
body: <p>I'm trying to understand how to best take advantage of mysqli prepared statements and I'm also pretty new to object oriented PHP.</p>
  
  <p>I understand that preparing a statement and then executing it multiple times is much more efficient than simply repeating the same query.</p>
  
  <p>The class below fetches a sound object by primary key.  If I needed to have several instances of this class in the same script, would I be getting the benefits of a prepared statement?</p>
  
  <p>Would this be a good candidate for a stored procedure?</p>
  
  <pre><code>class sound {
      public $id;
      public $name;
      public $musickey;
  
      public function __construct($id) {
          $this-&gt;id = $id;
          $sqli = new mysqli();
          if($stmt = $con-&gt;prepare("SELECT name, musickey FROM sounds WHERE id = ?")) {
          $stmt-&gt;bind_param("i", $this-&gt;id);
          $stmt-&gt;execute();
          $stmt-&gt;bind_result($name, $musickey);
  }
  </code></pre>
  
  <p>I hope my question isn't a duplicate.  I've been trying to find something on this topic, but sometimes forming the right question can be just as hard as finding the answer.</p>