Detecting errors in prepared statements
<p>I had a quick question with regard to prepared statements within PHP.  I was previously using the mysql_query function to manipulate database data, but was told that for security issues I should consider using prepared statements.  I have made the transition, but I have a few questions on how to detect whether a query has failed.</p>

<p>Below I have a piece of example code.  The $con variable is a connection which is specific depending on the query I am attempting, in this case the connection would be to my database through an account with only select permissions.</p>

<pre><code>$stmt = $con-&gt;stmt_init();
$stmt-&gt;prepare("SELECT COUNT(*) FROM users WHERE username=?");
$stmt-&gt;bind_param('s', $username);
$stmt-&gt;execute();
$stmt-&gt;bind_result($user_count);
$stmt-&gt;fetch();
$stmt-&gt;close();
</code></pre>

<p>I was wondering how one can detect failure within any of these steps?  The most simple solution I can imagine would be simply to wrap the code using a try/catch.. but I was wondering if there is a more sophisticated way of doing this.</p>

<p>Thanks for reading my question.</p>
