Quoting Barry Prentiss <[EMAIL PROTECTED]>:
> Hi,
> Can anyone help me to understand the OCIBindByName/OCIDefineByName
> functionality when used with the Oracle 'returning' clause? These two
> functions are seriously under-documented at PHP.net.
> I need the sequence-generated ID created during an insert for further
> manipulation.
> I tried sequence-name.currval but got an error.
> Here's some code that doesn't work:
>
> $sql = "insert into mdfaq values (null,'$Question','$Answer')
> returning
> ID into :ID";
> $stmt = ociParse($conn,$sql);
> OCIBindByName($stmt,":ID",&$faq_ID,-1);
You don't need to pass by reference and you should be able to ommit the length
parameter. You should probably bind $Question and $Answer as well. That way
your queries will be more efficient and you dont have to worry about escaping
quotes.
Also your SQL should be
"INSERT INTO mdfaq VALUES (sequence.nextval, '$Question', '$Answer') returning
ID into :id"
ID should be the column name of your primary key column.
ocidefinebyname is useful for pulling columns out of Oracle so you don't need
to make calls to ociresult() all the time. I actually don't see much benefit
over using fetchstatement()
Cheers,
Graeme
Cheers,
Graeme
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]