简体   繁体   中英

Call Oracle stored procedure using PDO PHP

I want to call procedure(written to insert data in table) using PDO PHP ,But procedure is not getting called.Don't know what Am I doing wrong Below is my code,Can anyone suggest me best way to call Oracle Procedure using PDO PHP.

<?php
  require("connection.php");
  date_default_timezone_set('Asia/Kolkata');

  $PARTY_C = 36317;
  $CONN_NO = 479;
  $EST_C = 86;
  $STATUS = 'F';
  $FAULTY_STATUS = 'PM';
  $BILL_DT = date('d/m/Y');
  $CURR_READ = 1000;
  $PENALTY = 35;
  $ADJSTMNT = 245;
  $MTR_CHNG_DT = date('d/m/Y');
  $OLD_MTR_READ = 900;
  $METER_RES_DT = date('d/m/Y');
  $PREV_OS_A_M = 1;
  $PREV_INT_A_M = 34;
  $PREV_PI_A_M = 45745;
  $PARTY_M = 'abc';

$stmt = $conn->prepare("CALL PH_STATUS(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->bindParam(1, $PARTY_C, PDO::PARAM_INT); 
$stmt->bindParam(2, $CONN_NO, PDO::PARAM_INT); 
$stmt->bindParam(3, $EST_C, PDO::PARAM_INT); 
$stmt->bindParam(4, $STATUS, PDO::PARAM_STR); 
$stmt->bindParam(5, $FALTY_STATUS, PDO::PARAM_STR); 
$stmt->bindParam(6, $BILL_DT, PDO::PARAM_STR); 
$stmt->bindParam(7, $CURR_READ, PDO::PARAM_INT); 
$stmt->bindParam(8, $PENALTY, PDO::PARAM_INT); 
$stmt->bindParam(9, $ADJSTMNT, PDO::PARAM_INT); 
$stmt->bindParam(10, $MTR_CHNG_DT, PDO::PARAM_STR); 
$stmt->bindParam(11, $OLD_MTR_READ, PDO::PARAM_INT); 
$stmt->bindParam(12, $METER_RES_DT, PDO::PARAM_STR); 
$stmt->bindParam(13, $PREV_OS_A_M, PDO::PARAM_INT); 
$stmt->bindParam(14, $PREV_INT_A_M, PDO::PARAM_INT); 
$stmt->bindParam(15, $PREV_PI_A_M, PDO::PARAM_INT); 
$stmt->bindParam(16, $PARTY_M, PDO::PARAM_STR); 

$stmt->execute();

print "procedure returned $stmt\n";

?>

As found here http://php.net/manual/en/pdo.prepared-statements.php , you have to use the bindParameter in another way or you have to use bindValue. (A good explanation can be found here Using pdo in php with stored procedure )

This should work:

...
$stmt->bindValue(1, $PARTY_C, PDO::PARAM_INT); 
$stmt->bindValue(2, $CONN_NO, PDO::PARAM_INT); 
$stmt->bindValue(3, $EST_C, PDO::PARAM_INT); 
...

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