PDO rowCount Error <p>I am using PDO for the first time. I created this method, and I am getting this error:</p> <pre><code> Call to a member function rowCount() on a non-object </code></pre> <p>The following is my code.</p> <pre><code> $db = new PDO("mysql:host=$dbhost;dbname=$dbname;charset=utf8", $dbuser, $dbpassword) function doesRecordExist($query) { global $db; try { $stmt = $db-&gt;query($query); $count = $stmt-&gt;rowCount(); return $count; } catch (PDOException $ex) { die($ex-&gt;getMessage()); } } </code></pre> <p>Can you help me please</p>