using codeigniter and need to get id of last auto-incremented id for next query, using oci8
Using codeigniter and 开发者_如何学JAVAoci8 for a project.
$this->db->insert_id(); would would perfect for getting the last auto-incremented id of the previous query, but it does not seem to work on an oracle database.
Any help is appreciated. I would LOVE to use mysql, but an oracle database is a requirement.
$this->db->insert_id(); for codeigniter, is just like php's mysql_insert_id()
See here:
Get the auto-generated ID after an insert
$data = array("value1","value2","value3");
$db = OCILogon("user","password");
$stmt = OCIParse($db,"insert into mytable values (myid.nextval,:myfield) returning id into :id");
OCIBindByName($stmt,":ID",$id,32);
OCIBindByName($stmt,":MYFIELD",$myfield,32);
while (list(,$myfield) = each($data)) {
OCIExecute($stmt);
echo "$myfieldgot id:$id\n";
}
You could also look at using a DB interface layer like PDO
How about getting the next sequence number?
SELECT ' || cTableName || '_seq.currval from dual
?
精彩评论