title: Fatal error: Call to a member function setAttribute() on a non-object
body: <p>I am trying to setup a newseltter, but in my newsletter class I keep getting the error: Fatal error: Call to a member function setAttribute() on a non-object</p>
  
  <p>I have been converting the file from an older non pdo version.</p>
  
  <pre><code>&lt;?php
  class NEWSLETTER{
      private static $email;
      private static $datetime = null;
      private static $valid = true;
  
          function __construct($conn){
          $this-&gt;db = $conn;
      }
  
      public function signup($email){
          if(!empty($_POST)){
              self::$email = $_POST['email'];
              self::$datetime = date('Y-m-d H:i:s');
  
              if(empty(self::$email)){
                  $status = "Error";
                  $message = "No email entered.";
                  self::$vaild = false;
              }else if(!filter_var(self::$email, FILTER_VALIDATE_EMAIL)){
                  $status = "Error";
                  $message = "Vaild email required.";
                  self::$valid = false;
              }
  
              if(self::$valid){
                  $this-&gt;db-&gt;setAttribute(PDO::ATTR_ERRMODE_EXCEPTION);
                  $exist = $this-&gt;prepare("SELECT COUNT (*) FROM newsletter WHERE email='$email'");
                  $exist-&gt;execute();
                  $data_exists = ($exist-&gt;fetchColumn() &gt; 0) ? true : false;
  
                  if(!$data_exists){
                      $sql = "INSERT INTO newsletter (email, date) VALUES (:email, :datetime)";
                      $q = $pdo-&gt;prepare($sql);
                      $q-&gt;execute(array(':email'=&gt;self::$email, ':datetime'=&gt;self::$datetime));
  
                      if($q){
                          $status = "Success";
                          $message = "You have been subscribed to the Epic Owl newsletter.";
                      }else{
                          $status = "Error";
                          $message = "An error occurred, try again.";
                      }
                  }else{
                      $status = "Error";
                      $message = "You have already subscribed at an earlier date.";
                  }
              }
  
              $data = array('status' =&gt; $status, 'message' =&gt; $message);
  
              echo json_encode($data);
          }
      }
  }
  ?&gt;
  
   &lt;?php
  ini_set('display_errors', '1');
  require_once './includes/conn.php';
  
  if(!empty($_POST['email'])){
      $email = $_POST['email'];
  
      $newsletter-&gt;signup($email);
  }
  ?&gt;
  
      &lt;!DOCTYPE html&gt;
      &lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;title&gt;EpicOwl UK | CMS Admin Panel Mail List&lt;/title&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;link rel="shortcut icon" href="../images/favicon.ico" type="image/x-icon" /&gt;
          &lt;link rel="stylesheet" type="text/css" href="../css/main.css"&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;div id="header"&gt;
          &lt;a href="index.php"&gt;&lt;img id="logo" src="../images/logo.png" /&gt;&lt;/a&gt;
          &lt;div id="navigation"&gt;
              &lt;ul&gt;
                  &lt;a href="../index.php"&gt;&lt;li&gt;Home&lt;/li&gt;&lt;/a&gt;
                  &lt;a href="./index.php"&gt;&lt;li&gt;Admin Panel&lt;/li&gt;&lt;/a&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div id="content"&gt;
      &lt;form method="post"&gt;
          &lt;br /&gt;&lt;h2&gt;Signup to the Epic Owl Newsletter(NOT WORKING! STILL BEING DEVELOPED!)&lt;/h2&gt;
          &lt;input type="text" name="email" placeholder="Your Email Address" /&gt;&lt;br /&gt;&lt;br /&gt;
          &lt;input type="submit" name="submit" value="Signup" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
      &lt;/form&gt;
  
              &lt;script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"&gt;&lt;/script&gt;
              &lt;script src="./includes/js/lib.js"&gt;&lt;/script&gt;
      &lt;/div&gt;
      &lt;div id="footer"&gt;
          &lt;p class="copyright"&gt;&amp;copy; EpicOwl UK. All Rights Reserved.&lt;/p&gt;
      &lt;/div&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>