php - Retrieve autoincrement ID through ODBC -


i'm adding new features legacy application written in php uses oracle 9i database through odbc functions. i've created table has sequence , trigger generate auto-incrementing ids.

now, i'm struggling find way make insert , obtain generated id afterwards:

do need hard-code sequence name , use seq_name.currval in rest of transaction? need ensure right value if there're concurrent accesses?

update: added third point failed attemps

best bet might code insert pl/sql api on database side return id use. e.g.)

create function insert_yourtable(p_f1 number, p_f2 varchar2, ... p_fn varchar2) return number    idval number; begin    insert yourtable(f1, f2,...fn)    values (p_f1, p_f2, ...p_fn)    returning your_id_value idval;    return idval; end; / 

then call prepared statement out param , use id rest of transaction.

whoops - saw "no out params comment...."

ok, guess need manage ui. drop trigger table, a

select yourseq.nextval dual; 

to next available key value, store locally, , of work using retrieved id insert id field in table. sequence ensure have transactional security on id.

what pain in butt implementation of odbc!


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -