WordPress $wpdb->get_row() Query Won't Work With Variable, But Works With Hardcoded

百般思念 提交于 2019-12-12 15:42:27

问题


My code is correct (I've been programming for 13 years), but for some reason when I use a variable in a SELECT query in the WHERE clause, I get no result. If I hardcode it, it works. How could this be? Blowing my mind...

$track = $wpdb->get_row($wpdb->prepare("SELECT tracking_id, order_id, outbound_tracking_number, return_tracking_numbers FROM wp_woocommerce_trackingnumbers WHERE order_id = %s", $o_id));

Thanks!


回答1:


I think it should be (%s should be %d)

$track = $wpdb->get_row($wpdb->prepare("SELECT tracking_id, order_id, outbound_tracking_number, return_tracking_numbers FROM wp_woocommerce_trackingnumbers WHERE order_id = %d", $o_id));

%s for strings and %d for digits and variable $o_id sounds like an integer to me.



来源:https://stackoverflow.com/questions/17004556/wordpress-wpdb-get-row-query-wont-work-with-variable-but-works-with-hardco

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!