• Can anyone tell me what went wrong with this wpdb prepare? It was working a month ago (maybe even a week or two ago) and I didn’t change anything, but now it returns null. Could another plugin be interfering somehow?

    The error log says there is a syntax error between the table name and the WHERE clauses, but it works fine without the prepare function.

    BROKEN:
    $wpdb->get_var($wpdb->prepare("SELECT enabled FROM %s WHERE pers_id = %d AND product_id = %d",$table_name,$myresults->pers_id,$product_id));

    WORKS:
    $wpdb->get_var("SELECT enabled FROM $table_name WHERE pers_id = $myresults->pers_id AND product_id = $product_id");

    ERROR:
    WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ”wp_wpsc_pers_products’ WHERE pers_id = 2 AND product_id = 27’…

  • The topic ‘WPDB query just stopped working’ is closed to new replies.