简体   繁体   中英

In Out Stored Procedure PHP MySQLi

I have the below PHP code for storing details into a table by calling the stored procedure: I would prefer to have the code in procedural way

$donpm = 0;
$cashCall = mysqli_prepare($dbc, 'call spCashDonation(?,@rno)');
mysqli_stmt_bind_param($cashCall, 'ssiid', $donFirstName, $donLastName, $donContactNo, $donpm, $donAmount);
mysqli_stmt_execute($cashCall) or die('Error recording Donation details.');

$getRno = mysqli_query($dbc, 'SELECT @rno');
$result = mysqli_fetch_assoc($getRno);
$ReceiptNo = $result['@rno'];

echo $ReceiptNo;

Calling the Stored Procedure:

Call spCashDonation ('SAI','KUMAR',9967021655,0,10000,@rno);
select @rno as ReceiptNo;

I am not getting any output for the PHP code (Receipt No). For the first time I am writing a PHP code to call a procedure from MySQL.

Please advice

Okay so after doing some research, it seems the problem was with the mysqli_prepare statement: Incorrect parameters.

Below is the refined code:

$donpm = 0;
$cashCall = mysqli_prepare($dbc, 'call spCashDonation(?,?,?,?,?,@rno)');
mysqli_stmt_bind_param($cashCall, 'ssiid', $donFirstName, $donLastName, $donContactNo, $donpm, $donAmount);
mysqli_stmt_execute($cashCall) or die('Error recording Donation details.');

$getRno = mysqli_query($dbc, 'SELECT @rno');
$result = mysqli_fetch_assoc($getRno);
$ReceiptNo = $result['@rno'];

echo $ReceiptNo;
echo $donFirstName . ' ' . $donLastName . ' ' . $donContactNo . ' ' . $donpm . ' ' . $donAmount;

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