Hi,

Can anyone give an example of retrieving the ID from an insertion, ie. what is the Oracle analog to the MySQL LAST_INSERT_ID()?

Thanks,
-phil

    For the benefit of others, I found an example, which is shown below:

    $data = array("larry","bill","steve");
    $db = OCILogon("scott","tiger");
    $stmt = OCIParse($db,"insert into names values (myid.nextval,:name) returning id into :id");

    OCIBindByName($stmt,":ID",$id,32);
    OCIBindByName($stmt,":NAME",$name,32);

    while (list(,$name) = each($data)) {
    OCIExecute($stmt);
    echo "$name got id:$id\n";
    }

    For more detail, see http://www.php-conference.de/2001/slides/arntzen_ocipaper.txt

    Thanks to Thies C. Arntzen for this example.

    -phil

      5 months later

      what you want to do is use pear's nextID function, ie $db->nextID("nameofyoursequence"); and it'll get the NEXT id, and you just insert it with the rest of your data. simple.

        ahh. that's nice too....

          Write a Reply...