$wpdb->get_var 对我不起作用 [英] $wpdb->get_var isn't working for me
问题描述
我正在开发一个 paypal IPN 处理程序,它获取 IPN 然后发送电子邮件.现在我正在测试它试图访问我的数据库的已支付"列,以确保之前尚未处理过该交易.但是 $wpdb 似乎没有正确返回东西.我能够在另一种形式上使用 $wpdb 将内容插入数据库,但我无法将其取回.我尝试过 get_var、get_row 和 get_results,并尝试将它们作为对象、数组或 get_var 中的变量来访问.
I am working on a paypal IPN handler that gets an IPN then sends an e-mail. Right now I am testing it trying to access the 'paid' column of my database to make sure the transaction has not already previously been processed. However $wpdb doesn't seem to be returning things correctly. I was able to use $wpdb on another form to insert things into the database but I am having trouble getting it back out. I have tried get_var, get_row, and get_results and tried to access them as objects, arrays, or a variable in the case of get_var.
$paidstatus = $wpdb->get_var("SELECT paid FROM wp_bbbiller WHERE txn_id = '$txn_id'");
$subject = 'Test e-mail';
$message = "Thank you for your purchase $payer_email. Your total was $".$payment_amount." for $duration hour
with $usercount users. Previously paid: $paidstatus";
mail ($payer_email , $subject , $message);
现在 $paidstatus 在电子邮件中显示为空白.当我使用 get_row 设置它时,我尝试使用 print_r($paidstatus) 并且它在电子邮件中显示为1",即使数据库值为 0.
Right now the $paidstatus shows up blank in the e-mail. I tried using print_r($paidstatus) when I had it setup with get_row and it showed up as a '1' in the email, even though the database value is 0.
推荐答案
是的,使用 get_results 有效!我能够像这样访问变量
Yes using get_results works! I was able to access the variable like this
$paidstatus = $wpdb->get_results("SELECT paid FROM wp_bbbiller WHERE txn_id = '$txn_id'");
foreach ($paidstatus as $status) {
$subject = 'Test e-mail';
$message = "Thank you for your purchase $payer_email. Your total was $".$payment_amount." for $duration hour
with $usercount users. Previously paid: ".$status->paid;
mail ($payer_email , $subject , $message);
}
或者 get_row 也可以这样工作
Alternatively get_row also works like this
$paidstatus = $wpdb->get_row("SELECT paid FROM wp_bbbiller WHERE txn_id = '$txn_id'");
$subject = 'Test e-mail';
$message = "Thank you for your purchase $payer_email. Your total was $".$payment_amount." for $duration hour
with $usercount users. Previously paid: ".$paidstatus->paid;
mail ($payer_email , $subject , $message);
这篇关于$wpdb->get_var 对我不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!