title: Fatal error: Call to undefined method PDOStatement::lastInsertId()
body: <p>I have created a database class for PDO connection. Inserted record and tried to get last insert id after that getting this error "Fatal error: Call to undefined method PDOStatement::lastInsertId()".</p>
  
  <p>Database class:</p>
  
  <pre><code>class Database {
  public static $link = null ;
  
  public static function getLink( ) {
      if ( self :: $link ) {
          return self :: $link ;
      }
  
      $ini = "config.ini" ;
      $parse = parse_ini_file ( $ini , true ) ;
      $driver = $parse [ "db_driver" ] ;
      $dsn = "${driver}:" ;
      $user = $parse [ "db_user" ] ;
      $password = $parse [ "db_password" ] ;
      $options = $parse [ "db_options" ] ;
      $attributes = $parse [ "db_attributes" ] ;
  
      foreach ( $parse [ "dsn" ] as $k =&gt; $v ) {
          $dsn .= "${k}=${v};" ;
      }
  
      self :: $link = new PDO ( $dsn, $user, $password, $options ) ;
  
      foreach ( $attributes as $k =&gt; $v ) {
          self :: $link -&gt; setAttribute ( constant ( "PDO::{$k}" )
              , constant ( "PDO::{$v}" ) ) ;
      }
  
      return self :: $link ;
  }
  
  public static function __callStatic ( $name, $args ) {
      $callback = array ( self :: getLink ( ), $name ) ;
      return call_user_func_array ( $callback , $args ) ;
  }
  </code></pre>
  
  <p>}
  configuration file config.ini</p>
  
  <pre><code>db_driver=mysql
  db_user=username
  db_password=password
  
  [dsn]
  host=hostname
  port=3306
  dbname=databasename
  
  [db_options]
  PDO::MYSQL_ATTR_INIT_COMMAND=set names utf8
  
  [db_attributes]
  ATTR_ERRMODE=ERRMODE_EXCEPTION
  ############
  </code></pre>
  
  <p>Code to insert query:</p>
  
  <pre><code>$pdo = Database::prepare("INSERT INTO customer (first_name, last_name, join_date) VALUES (?, ?, ?)");
  $pdo-&gt;bindParam(1, $firstName);
  $pdo-&gt;bindParam(2, $lastName);
  $pdo-&gt;bindParam(3, $currentDate);
  $pdo-&gt;execute();
  $custId = $pdo-&gt;lastInsertId();
  $pdo-&gt;closeCursor();
  </code></pre>
  
  <p>Thanks in advance.</p>