title: Fatal error: Uncaught exception 'PDOException' with message
body: <p>I am trying to run a MySQL PDO query. I am not sure why I am getting a fatal error. I have checked other posts, but their answers don't seem to solve mine.</p>
  
  <p>The script is connecting to the database fine. The username and password are correct and I have removed them in the script below.</p>
  
  <p>My output:</p>
  
  <pre><code>Connected to database
  Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user 'nobody'@'localhost' (using password: NO)' in /home/a/public_html/d/inc/header.php:34 Stack trace: #0 /home/a/public_html/d/inc/header.php(34): PDO-&gt;__construct('mysql:host=;dbn...', NULL, NULL) #1 /home/a/public_html/d/inc/header.php(43): testdb_connect() #2 /home/a/public_html/d/article.php(3): include('/home/a/p...') #3 {main} thrown in /home/a/public_html/d/inc/header.php on line 34
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>&lt;?php
      /*** MySQL  hostname ***/
      $hostname = 'localhost';
      /*** MySQL  username ***/
      $username = 'removed';
      /*** MySQL  password ***/
      $password = 'removed';
      try {
          function testdb_connect(){
              $dbh = new PDO("mysql:host=$hostname;dbname=removed", $username, $password);
              return ($dbh);
          }
              echo 'Connected to database';
          }
      catch(PDOException $e) {
          echo $e-&gt;getMessage();
      }
  
      $dbh = testdb_connect();
  
      $id = $_GET[id];
      echo 'dfsdfs ' . $id;
      var_dump($dbh);
      $sql = "SELECT * FROM 'radiologyArticles' WHERE 'id' = :id";
      $stmt = $dbh-&gt;prepare($sql);
      $stmt-&gt;bindParam(':id', $id);
      $stmt-&gt;execute();
      while($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC)) {
  
  ?&gt;
  
          &lt;section&gt;
              &lt;header&gt;
                  &lt;h2&gt;&lt;?php echo $row['articleTitle']; ?&gt;&lt;/h2&gt;
                  &lt;h3&gt;A generic two column layout&lt;/h3&gt;
              &lt;/header&gt;
              &lt;p&gt;
                  &lt;?php echo $row['articleBody']; ?&gt;
              &lt;/p&gt;
          &lt;/section&gt;
  
          &lt;?php
      }
              // Close the PDO connection
              $link = null;
          ?&gt;
  </code></pre>