title: MySQLi prepared statements: Short versions in one line
body: <p>In PHP, I use a lot of one liners like:</p>
  
  <p>Fetch value:</p>
  
  <pre><code>$sql-&gt;query("SELECT ID FROM table WHERE condition = 1")-&gt;fetch_object()-&gt;ID;
  </code></pre>
  
  <p>Fetch row:</p>
  
  <pre><code>$sql-&gt;query("SELECT * FROM table WHERE condition = 1")-&gt;fetch_assoc();
  </code></pre>
  
  <p>Fetch rows:</p>
  
  <pre><code>$sql-&gt;query("SELECT * FROM table WHERE condition &gt; 1")-&gt;fetch_all(MYSQLI_ASSOC);
  </code></pre>
  
  <p>Insert row:</p>
  
  <pre><code>$sql-&gt;query("INSERT INTO table(`row1`,`row2`) VALUES('".$data1."','".$data2."')");
  </code></pre>
  
  <p>Delete row:</p>
  
  <pre><code>$sql-&gt;query("DELETE FROM table WHERE condition = 1");
  </code></pre>
  
  <p>Are there also beautiful one liners for prepared statements?</p>
  
  <p>This fails:</p>
  
  <pre><code>$sql-&gt;prepare("SELECT ID FROM table WHERE condition = ?")-&gt;bind_param("i", $a=1)-&gt;execute()-&gt;fetch_object()-&gt;ID;
  </code></pre>
  
  <p>This works:</p>
  
  <pre><code>$query = $sql-&gt;prepare("SELECT ID FROM table WHERE condition = ?");
  $query-&gt;bind_param("i", $a=1);
  $query-&gt;execute();
  $query-&gt;get_result()-&gt;fetch_object()-&gt;ID;
  </code></pre>