简体   繁体   中英

How can I call this stored procedure in PHP?

There is an oracle stored procedure that I need to call and retrieve its output variable, but I'm not sure how to do this from PHP. I'm also using the Laravel framework.

Here's what I have so far.

$db = DB::connection('oracle');
$stmt = $db->getPdo()->prepare("EXEC jgreen.person_match(p_first_name => 'Bob'
    , p_last_name => 'Mitchell'
    , p_middle_name => ''
    , p_birth_date => to_date('1982-02-09', 'YYYY-MM-DD')
    , p_gender => null
    , p_email => 'test@gmail.com'
    , p_phone => null
    , p_ssn_last_4 => null
    , p_id_out => ?
    , p_suspend_out => ?
    , p_status_out => ?
    , p_message_out => ?)");
$stmt->bindParam(1, $id);
$stmt->bindParam(2, $suspend);
$stmt->bindParam(3, $status);
$stmt->bindParam(4, $message);

$stmt->execute();

echo $status . ' ' . $message . ' ' . $pidm . ' ' . $suspend;

Currently I'm getting a

oci_bind_by_name(): ORA-01036: illegal variable name/number

but I'm not even sure that I built the query right to start.

Try this

$db = DB::connection('oracle');
$stmt = $db->getPdo()->prepare("EXEC jgreen.person_match(p_first_name => :first_name
    , p_last_name => :last_name
    , p_middle_name => :middle_name
    , p_birth_date => to_date(:birth_date, 'YYYY-MM-DD')
    , p_gender => :gender
    , p_email => :email
    , p_phone => :phone
    , p_ssn_last_4 => :ssn
    , p_id_out => :id_out
    , p_suspend_out => :suspend_out
    , p_status_out => :status_out
    , p_message_out => :message_out)");
$stmt->bindValue(':first_name', 'Bob');
$stmt->bindValue(':last_name', 'Mitchell');
$stmt->bindValue(':middle_name', '');
$stmt->bindValue(':birth_date', '1982-02-09');
$stmt->bindValue(':gender', null);
$stmt->bindValue(':email','test@gmail.com');
$stmt->bindValue(':ssn', null);
$stmt->bindParam(':id_out', $id);
$stmt->bindParam(':suspend_out', $suspend);
$stmt->bindParam(':status_out', $status);
$stmt->bindParam(':message_out', $message);

$stmt->execute();

echo $status . ' ' . $message . ' ' . $pidm . ' ' . $suspend;

It looks like you're defining a PHP-looking array to pass in parameters, but I'm fairly certain that's not valid in Oracle. Instead, call your stored procedure as a series of parameters instead of an array:

$stmt = $db->getPdo()->prepare("EXEC jgreen.person_match(
  'Bob',
  'Mitchell',
  '',
  to_date('1982-02-09', 'YYYY-MM-DD'),
  null,
  'test@gmail.com',
  null,
  null,
  ?,
  ?,
  ?,
  ?
)");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM