title: Call to a member function fetchColumn() on a non-object PDO
body: <p><strong>Trying to fetch columns for my project, never done so in PDO, tried looking at the documentations but it didn't really help.</strong></p>
  
  <pre><code>  $sql = $CONNECT_TO_DATABASE-&gt;query("SELECT COUNT(*) FROM comments");
      $result = $sql-&gt;fetch(PDO::FETCH_ASSOC);
      $r = $result-&gt;fetchColumn();
  </code></pre>
  
  <p>What have I done wrong?</p>
  
  <p>Fatal error: Call to a member function fetchColumn() on a non-object in C:\xampp\htdocs\project\events.php on line 6</p>
  
  <pre><code>$r = $result-&gt;fetchColumn();
  </code></pre>
  
  <p><em>Thanks!</em></p>
  
  <p>Connection:</p>
  
  <pre><code>&lt;?php
  /**
  * Connect to Database
  * @Author Jony &lt;artemkller@gmail.com&gt;
  **/
      ##################CHANGE THIS####################
          /**                                         #   
          * MYSQL HOST HERE (Example: localhost)      #
          **/                                         #
                                                      #
          DEFINE ("MYSQL_HOST", "localhost");         #
                                                      #
          /**                                         #
          * MYSQL USER HERE (Example: root)           #
          **/                                         #
                                                      #
          DEFINE ("MYSQL_USER", "root");              #
                                                      #   
          /**                                         #       
          * MYSQL PASSWORD HERE (Example: password)   #
          **/                                         #           
                                                      #   
          DEFINE ("MYSQL_PASSWORD", "");              #
                                                      #   
      #################################################
  
      # Connect to the database using PDO.
      $CONNECT_TO_DATABASE = new PDO('mysql:host='.MYSQL_HOST.';dbname=project', MYSQL_USER, MYSQL_PASSWORD);
  
      # See if theres an error while connecting to the database
      try {
          $CONNECT_TO_DATABASE-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      }
      catch(PDOException $ERROR_MESSAGE)
      {
          echo 'ERROR: ' . $ERROR_MESSAGE-&gt;getMessage();
      }
  
  
  ?&gt;
  </code></pre>