7
I’m trying to rescue the last id in the bank with lastInsertId() of the PDO, but nothing appears.
OBS: I’m using the Postgre.
<?php
try {
    $dbh = new PDO('pgsql:host=localhost;port=5432;dbname=bancocjweb1', 'postgres', '12345');
    $stmt = $dbh->prepare("INSERT INTO pessoas (sexo, nascimentodata, email, nome, cpf) VALUES(?,?,?,?,?)");
    try {
        $dbh->beginTransaction();
        $stmt->execute(array(
            'm',
            '1987-01-01',
            '[email protected]',
            'teste',
            '05255178910'
        ));
        $dbh->commit();
        echo $dbh->lastInsertId();
    }
    catch (PDOExecption $e) {
        $dbh->rollback();
        print "Error!: " . $e->getMessage() . "</br>";
    }
}
catch (PDOExecption $e) {
    print "Error!: " . $e->getMessage() . "</br>";
}
?> 
Better to use
INSERT ... RETURNING(http://www.postgresql.org/docs/currently/static/sql-insert.html). Sorry, I don’t know if there’s a Translation.– Craig Ringer