mysql_fetch_array 有时会失败
我正在尝试实现与在线支付框架的连接。
其中一个文件给我带来了一些麻烦,因为有时代码可以工作,有时则不能...我不明白为什么...
这就是代码失败的地方...
$sql = "select transidmerchant,totalamount from nsiapay where transidmerchant='".$order_number."'and trxstatus='Verified'";
$result = mysql_query($sql);
**$checkout = mysql_fetch_array($result);**
echo "sql : ".$sql;
$hasil=$checkout['transidmerchant'];
echo "hasil: ".$hasil;
$amount=$checkout['totalamount'];
echo "amount: ".$amount;
// Custom Field
if (!$hasil) {
echo 'Stop1';
} else {
if ($status=="Success") {}
}
这只是代码的一部分,但是我认为您尝试查看问题就足够了...它在粗体行上失败,$checkout = mysql_fetch_array($result);
奇怪的是,“echo sql”有效,并且它显示了正确的值,但是当我将它们放在数组中时,有时变量会被传递,有时则不会......所以,当到达 < code>if (!$hasil) 它会失败,因为该值为空...但有时它会起作用...
对可能发生的情况有什么想法吗?
谢 路易斯
I'm trying to implement the connection to a online payment framework.
One of the files is giving me some trouble, because sometimes the code works, sometimes it doesn't... And I can't understand why...
Here's where the code is failing...
$sql = "select transidmerchant,totalamount from nsiapay where transidmerchant='".$order_number."'and trxstatus='Verified'";
$result = mysql_query($sql);
**$checkout = mysql_fetch_array($result);**
echo "sql : ".$sql;
$hasil=$checkout['transidmerchant'];
echo "hasil: ".$hasil;
$amount=$checkout['totalamount'];
echo "amount: ".$amount;
// Custom Field
if (!$hasil) {
echo 'Stop1';
} else {
if ($status=="Success") {}
}
It's just part of the code but I think it's enough for you to try to see the problem... It fails on the bold line, $checkout = mysql_fetch_array($result);
The weird thing is that the "echo sql" works, and it shows the right values, but then when I put them on the array, sometimes the variables are passed, sometimes they're not... And so, when getting to if (!$hasil)
it fails because the value is empty... but sometimes it works...
Any ideas on what might be happen?
Thans
Luis
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
失败的唯一原因是查询不返回任何内容。
正确的方法是检查是否有返回的东西:
The only way this fail is when query doesn't return anything.
The correct way would be to check if there is something returned: