title: Fatal error: Call to a member function prepare() on a non-object in
body: <p>I have three files first if config class, second is user class and third is index file.</p>
  
  <p>config.php</p>
  
  <pre><code>class connection{    
  
      public function dbConnect()
      {         
         new PDO("mysql:host=localhost:3306;dbname=education","root","");
      }
  }
  </code></pre>
  
  <p>user.php</p>
  
  <pre><code>&lt;?php
  session_start();
  require_once '../cms/config.php';
  
  class user{
      private $db;
  
      public function __construct()
      {
          $this-&gt;db= new connection();
          $this-&gt;db=  $this-&gt;db-&gt;dbConnect();
          return $this-&gt;db;
      }
  
      public function login($user,$pass)
      {
          //creating a array for future usage
  
          if(!empty($user) &amp;&amp; !empty($pass))
          {                
             $st=$this-&gt;db-&gt;prepare("select * from admin where admin_user=? AND admin_pass=?");
             $st-&gt;bindParam(1,$user);
             $st-&gt;bindParam(2,$pass);
             $st-&gt;execute();
             if($st-&gt;rowCount()==1)
             {
               $_SESSION['admin_user']=$user;
               header("Location:admin.php");
             }
             else
             {
                 $_SESSION['errorMessage']="Incorrect username or password!Please try again.";
                 echo $_SESSION['errorMessage'];
             }               
          }
          else
          {
               echo "Hey! Don't leave me empty";                
          }
      }
  }
  ?&gt;
  </code></pre>
  
  <p>index.php</p>
  
  <pre><code>require_once '../cms/user.php';
  
  if(isset($_POST['submit']))
  {    
      $user=$_POST['user'];
      $user=  mysql_real_escape_string($user);
      $pass=$_POST['pass'];
      $pass=  mysql_real_escape_string($pass);
  
      $object=new user();
  
      $object-&gt;login($user,$pass);
  }
  </code></pre>
  
  <p>When I am trying to login with false or correct data, it throws fatel error. Even it was working file yesterday. But what happened today. This is annoying.
  Please help.</p>