title: How to fetch a row with PDO
body: <p>I'm trying not to get frustrated, but I've recently learned that <code>mysql_*</code> is deprecated in PHP. I've decided that I would learn how to use PDO.</p>
  
  <p>I've just been looking at it this afternoon, and connecting to the database using it was easy, but then I wanted to fetch a row with it and save the row as an array indexed by the column names (the same way as the function <code>mysql_fetch_array</code> did). I can't figure it out to save my life.</p>
  
  <p>I'll post my code to clarify, and I'm sure it is something simple (all programming errors are always simple), but I am definitely doing something wrong.</p>
  
  <pre><code>// Connect to the database
  $host    = $_PARAM["DatabaseServer"];
  $db        = $_PARAM["MainDatabase"];
  $dbuser    = $_PARAM["DatabaseUser"];
  $dbpass    = $_PARAM["DatabasePass"];
  try
  {
      $Database = new PDO("mysql:host=$host;dbname=$db", $dbuser, $dbpass);
  }
  catch (PDOException $e)
  {
      echo "There was an unexpected error. Please try again, or contact us with concerns";
  }
  
  $stmt = $Database-&gt;prepare("SELECT * FROM users WHERE username=?");
  $stmt-&gt;execute(array($sUserCook));
  $row = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
  
  echo $row["username"];
  </code></pre>