title: user_exists function using PDO connect to mysql
body: <p>im still in the early learning stages, banging my head against walls looking for clues. Iv been reading the manual to no avail. Im building a user log in system based on the phpAcadamy tutorial 'Register &amp; Login'. They use mysql_connect in the tutorial, but I am using a PDO connection to mysql.</p>
  
  <p>i am making my first function, user_exists, which queries the username column of my table for names that match the POSTed $username, then returns a true or false if it is found.</p>
  
  <p>here is my testing code:</p>
  
  <pre><code>$host       = "localhost";
  $username   = "mholberg_skroovy";
  $password   = "*omitted*";
  $dbname     = "mholberg_skroovytest";
  
  $db = new PDO("mysql:host={$host};dbname={$dbname};", $username, $password);
  
  function user_exists($username) {
      $query = $db-&gt;query("SELECT `users`.`username` FROM `users` WHERE `username` = '$username'");
      return($query, 0) == 1) ? true : false; // ???
  }
  
  if (user_exists('junkomatic') === true) {
      echo 'exists';
  }
  
  die();
  </code></pre>
  
  <p>The if statement at the bottom should test the function above it. The line with ??? is the line that is obviously wrong. Im getting an error on the ',' Any input/explanation would be hugely appreciated.</p>