Search code examples
phpdatabaseoracle-databaseoracle-call-interface

Geting: Warning: oci_fetch(): ORA-24374: define not done before fetch or execute and fetch. despite having defined the names


After reading every manual I could find I still can't come to a solution on this problem.

I have the following code:

<?php

$token = 'number';
$secret = 'number';
$ID;

$conn = oci_connect('FITBIT', 'pass', '127.0.0.1/xe');
$stid = oci_parse($conn, 'BEGIN find_personsdevice_id(:token, :secret, :l_personsdeviceid); END;');
oci_bind_by_name($stid, ':token', $token);
oci_bind_by_name($stid, ':secret', $secret);
oci_bind_by_name($stid, ':l_personsdeviceid', $ID);

oci_define_by_name($stid, 'l_personsdeviceid', $ID);
oci_define_by_name($stid, ':token,', $token);
oci_define_by_name($stid, ':secret,', $secret);

oci_execute($stid);
oci_fetch($stid);
var_dump($stid);

?>

The procedure is functioning, I tested it with sql developer and it gives the right result. But when I try to call it in this PHP script I get the following message:

Warning: oci_fetch(): ORA-24374: define not done before fetch or execute and fetch in

I googled the ora code and found this:

Cause: The application did not define output variables for data being fetched before issuing a fetch call or invoking a fetch by specifying a non-zero row count in an execute call. Action: Issue OCI define calls for the columns to be fetched.

as far as I can tell I put the oci_fetch command after the define commands. So what am I doing wrong?

the PL/SQL procedure:

create or replace
procedure find_personsdevice_id(b_token in varchar2, b_secret in varchar2, l_personsdeviceid out number) as

/*author Ruben Jonkers
  project: FITBIT
  goal procedure: find ID by token and seccret
  date: 20-05-2015
  version:0.1
  adjustments:
*/


cursor c_personsdeviceid (b_token in varchar2:='', b_secret in varchar2:='') is
  select pde.id 
  from personsdevices pde,
       persons psn,
       groups grp,
       tokens tns
  where psn.id=pde.persons_id
  and pde.persons_id = psn.id
  and grp.tokens_id = tns.id
  and tns.token = b_token
  and tns.secret = b_secret;

  r_personsdeviceid c_personsdeviceid%rowtype;

begin
  open c_personsdeviceid (b_token, 
                          b_secret);
  fetch c_personsdeviceid into r_personsdeviceid;
    if c_personsdeviceid%found then
      l_personsdeviceid:=r_personsdeviceid.id;
    end if;
  close c_personsdeviceid;

end;

Solution

  • Turned out I didn't need oci_fetch at all since the result was already stored in $id!