title: Connecting to database with PDO in php
body: <p>I've written this small class for my database connections in my project:</p>
  
  <pre><code> &lt;?php
      class DatabaseUtility{
  
          private $dsn, $username, $password, $database, $pdo;
  
          public function __construct($host = 'localhost', $username = 'root', $password = '', $database){
              $this-&gt;dsn = "mysqli:dbname=$database;host:$host";
              $this-&gt;username = $username;
              $this-&gt;password = $password;
              $this-&gt;database = $database;
          }
  
          public function connect(){
              try{
                  $this-&gt;pdo = new PDO($this-&gt;dsn,$this-&gt;username,$this-&gt;password,null);
                  $this-&gt;pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                  $this-&gt;pdo-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
              } catch(PDOException $err){
                  die($err-&gt;getMessage());
              }
          }
  
          public function prepareStatment($query){
              $this-&gt;pdo-&gt;prepare($query);
          }
  
      }
  ?&gt;
  </code></pre>
  
  <p>And this is how i'm using it:</p>
  
  <pre><code>&lt;?php
      require 'DatabaseUtility.php';
      $db = new DatabaseUtility('localhost','root','','apex');
      $db-&gt;connect();
      $statment = $db-&gt;prepareStatment("Select offer_id from offer_images where img_id = :img_id");
  
  ?&gt;
  </code></pre>
  
  <p>But i'm getting the following error:</p>
  
  <pre><code>Could not find driver
  </code></pre>
  
  <p>I'm new to PDO stuff so please do guide me what i'm doing wrong? Is this method okay for a secure and fast database activity?</p>
  
  <p><strong>Update:</strong>
  I'm now using these lines of code to use my DatabaseUtility class but got an error:</p>
  
  <pre><code> &lt;?php
          require 'DatabaseUtility.php';
          $id= 25;
          $db = new DatabaseUtility('localhost','root','','apex');
          $db-&gt;connect();
          $statment = $db-&gt;prepareStatment("Select offer_id from offer_images where img_id = :img_id");
         $statment-&gt;bindParam("img_id", $id ,PDO::PARAM_INT);
          $statment-&gt;execute();
          print_r($statment);
      ?&gt;
  </code></pre>
  
  <p>Error is:</p>
  
  <pre><code>call to a member function bindParam() on a non-object in this line:
  $statment-&gt;bindParam("img_id", $id ,PDO::PARAM_INT);
  </code></pre>