I am attempting to move a single page into WordPress as a plugin as an Admin menu. I first verify that isset($wpdb) but my test query fails. I do $wpdb->last_query and I don’t understand the results.
This is what I try:
$clientquery = $wpdb->query("select post_title from wp_posts where id=390");
exit(var_dump( $wpdb->last_query));
This is the result:
string(44) "select post_title from wp_posts where id=390"
Where is string(44) coming from? BTW, I am absolutely new to developing in PHP and WordPress learning this on my own.
Also, if I change the query to “select * from …” the result changes to string(35)… . What?
assuming you have declared $wpdb as a global the above should work so your code should look like this:
note the results are stored in $clientquery
The
$wpdb->last_query
shows the exact MySQL Query itself andstring(44)
indicates that it is string type of length 44:WordPress defines a class called wpdb, which contains a set of functions used to interact with a database. Its primary purpose is to provide an interface with the WordPress database, but can be used to communicate with any other appropriate database. So it is not necessary to check using
isset()
function