$wpdb->get_var returns 0 时间:2019-06-19 作者:Yearmaz 我使用以下代码获取数字:$where = \'WHERE type = 4 AND active = 1 AND user_id = \' . $user_id ; $user_followed = $wpdb->get_var("SELECT COUNT( * ) AS total FROM {$wpdb->tablex} {$where}"); 但它返回0(零)。问题是什么? 1 个回复 SO网友:MikeNGarrett 该查询的计数可能为0。确保$wpdb->tablex 是正确的。另外,一定要使用$wpdb->prepare$user_followed = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( * ) AS total FROM {$wpdb->tablex} WHERE type = %d AND active = %d AND user_id = %d", 4, 1, $user_id ) ); 文章导航