1 回答
TA贡献1842条经验 获得超21个赞
我想分享一下我如何克服这个问题并找到解决方案的最终结果。
MySQL存储过程:
CREATE DEFINER=`CN20100686`@`%` PROCEDURE `sp_Facturatie_OpenstaandeBetalingen_Get`()
BEGIN
Declare spResult nvarchar(200);
DECLARE exit handler for SQLEXCEPTION /*declared an exception handler, which the result is put into a select*/
BEGIN
GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
@errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
SET spResult = left(CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text),200);
SELECT spResult;
END;
SELECT AB.BetalingAfspraakID,
AB.BetalingDatum,
Round(AB.BetalingBedrag,2) BetalingBedrag,
BS.BetaalStatusOmschrijving,
BM.BetaalMethodeOmschrijving,
FROM Web_tblAfspraakBetalingen AB
LEFT OUTER JOIN Web_tblBetaalStatus BS
ON AB.betalingbetaalstatusid = BS.betaalstatusid
LEFT OUTER JOIN Web_tblBetaalMethode BM
ON AB.betalingbetaalmethodeid = BM.betaalmethodeid
WHERE BS.betaalstatusomschrijving <> 'Betaald'
ORDER BY betalingid ASC;
END
在 PHP 中,我做了以下事情:
检查结果集是否返回零行 - 表示存储过程已正确执行,但未找到结果,否则
检查结果集是否有一个名为“spResult”的字段。如果是这样,请在屏幕上读取并填充结果,否则
根据需要处理结果集。
$sproc = 'sp_Facturatie_OpenstaandeBetalingen_Get()';
$result = mysqli_query($link,"CALL " . $sproc) or die("mysqli_query failure: " . mysqli_error());
$rowcount=mysqli_num_rows($result);
if ($rowcount == 0) {echo "No records found.";}
if ($result)
{
$rowcounter = 'first';
while ($row = mysqli_fetch_array($result))
{
if (substr($row["spResult"],0,5) == 'ERROR')
{
echo "Error occured on executing " . $sproc . ": " . $row["spResult"];
mysqli_free_result($result);
exit();
}
if ($rowcounter == 'first')
{
//printing here my table header
echo "
<b>List</b>
</br>
<table border=1 style='min-width:100%'>
<tr>
<td width='80%'>
Payments:
</td>
<td width='20%'>
</td>
</tr>
Count open payments: " . $rowcount;
$rowcounter = 'next';
}
$BetalingAfspraakID = $row["BetalingAfspraakID"];
$BetalingDatum = $row["BetalingDatum"];
$BetalingBedrag = $row["BetalingBedrag"];
$BetaalStatusOmschrijving = $row["BetaalStatusOmschrijving"];
$BetaalMethodeOmschrijving = $row["BetaalMethodeOmschrijving"];
//display results as you wish
echo "<tr>";
echo "<td>";
echo "<b>Afspraak</b> " . $BetalingAfspraakID . "</br>";
echo "Amount: " . $BetalingBedrag . "</br>";
echo "Status: " . $BetaalStatusOmschrijving;
echo "</td>";
echo "</tr>";
}
// free result set
mysqli_free_result($result);
}
else
{
echo "Error occured!" . mysqli_error($link);
exit();
}
我希望有人觉得这个答案有用;当然可以进一步改进:)
- 1 回答
- 0 关注
- 135 浏览
添加回答
举报