How to convert a mysqli query to wpdb
-
Hello, I’d appreciate some help in converting this mysqli query to using wpdb:
$ret = array( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ); $q = "SELECT id,user,status,completed,track,coursecost,testcost," . "gst,pst,discount FROM exams WHERE student=$id AND status=" . $theExam->STATUS_COMPLETED . " ORDER BY completed"; if (!( $result = mysqli_query($Connection, $q) ) ) { if ($show ) { makeInstruction( 4, "Database Error: Could not retrieve " . "student's exams: $q" ); } return( $ret ); }
From my reading of the developer reference it should look something like:
global $wpdb; $q = $wpdb->get_results( "SELECT id,user,status,completed,track,coursecost,testcost," . "gst,pst,discount FROM {$wpdb->prefix}exams WHERE student=$id AND status=" . $theClass->STATUS_COMPLETED . " ORDER BY completed");
How do I handle the error if the foregoing is the correct approach?
if (!( $result = mysqli_query($Connection, $q) ) ) { if ($show ) { makeInstruction( 4, "Database Error: Could not retrieve " . "student's exams: $q" ); } return( $ret ); }
Thanks.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘How to convert a mysqli query to wpdb’ is closed to new replies.