title: PDO lastInsertId(); issue php
body: <p>I have a database with a parent child relationship. I need to first insert into the parent table then get the ID, that I would use to then insert data into the child table.</p>
  
  <p>The following is snippets of the code I am using to insert into the database. This is my first time using PDO class. The errors I am getting; Undefined property: <strong>and</strong> Call to a member function lastInsertId() on a non-object  database::$db. I must admit am I fairly new to PHP. Thank you</p>
  
  <hr>
  
  <pre><code>{
  
      public function __construct($DB_TYPE, $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS)
      {
          parent::__construct($DB_TYPE.':host='.$DB_HOST.';dbname='.$DB_NAME, $DB_USER, $DB_PASS);
  }
  </code></pre>
  
  <hr>
  
  <pre><code>$this-&gt;db = new database(DB_TYPE, DB_HOST, DB_NAME, DB_USER, DB_PASS);
  </code></pre>
  
  <hr>
  
  <pre><code>    $this-&gt;db-&gt;insert('images', array(
          'image_userID' =&gt; $data['image_userID'],
          'image_date' =&gt; $data['image_date']
      ));
  </code></pre>
  
  <hr>
  
  <pre><code>/**
   * insert
   * @param string $table A name of table to insert into
   * @param string $data An associative array
   */
  public function insert($table, $data)
  {
      $fieldNames = implode('`, `', array_keys($data));
      $fieldValues = ':' . implode(', :', array_keys($data));
  
      $sth = $this-&gt;prepare("INSERT INTO $table (`$fieldNames`) VALUES ($fieldValues)");
  
      foreach ($data as $key =&gt; $value) {
          $sth-&gt;bindValue(":$key", $value);
      }
  
      $sth-&gt;execute();
  
  $result= $this-&gt;db-&gt;lastInsertId();
   return $result;
  }
  </code></pre>