title: Get last insert id after a prepared insert with PDO
body: <p>I'm using PHP PDO with PostgreSQL for a new project. </p>
  
  <p>Given the following function, how can I return the id of the row just inserted?
  It doesn't work the way it looks now.</p>
  
  <pre><code>function adauga_administrator($detalii) {
      global $db;
      $ultima_logare = date('Y-m-d');
  
      $stmt = $db-&gt;prepare("INSERT INTO site_admins (sa_nume, sa_prenume, sa_user_name, sa_password, sa_email, sa_id_rol, sa_status, sa_ultima_logare) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
      $stmt-&gt;bindParam(1, $detalii['nume']);
      $stmt-&gt;bindParam(2, $detalii['prenume']);
      $stmt-&gt;bindParam(3, $detalii['username']);
      $stmt-&gt;bindParam(4, md5(md5($detalii['parola'] . SIGURANTA_PAROLE) . SIGURANTA_PAROLE));
      $stmt-&gt;bindParam(5, $detalii['email']);
      $stmt-&gt;bindParam(6, $detalii['rol'], PDO::PARAM_INT);
      $stmt-&gt;bindParam(7, $detalii['status'], PDO::PARAM_INT);
      $stmt-&gt;bindParam(8, $ultima_logare);    
      $stmt-&gt;execute(); 
  
      $id = $db-&gt;lastInsertId();
      return $id;
  }
  </code></pre>