How to stop $wpdb from prepending database name

The behavior I described in my post only happens when you are using $wpdb->update to execute an UPDATE statement. If you want to update a different database using the same connection, use $wpdb->query to send a raw query, WP won’t modify it then.

How to fetch records from database WordPress

wpdb is a simple wrapper around the mysql_* functions, but you can’t mix and match them. $wpdb->query does not return the database reference that mysql_fetch_row needs. It … … returns an integer corresponding to the number of rows affected/selected. If there is a MySQL error, the function will return FALSE. (Note: since both 0 and … Read more

Why this query is not showing any result on wordpresss home page?

First of all your query is wrong. The right query is $mypost = $wpdb->query($wpdb->prepare(“SELECT post_content FROM $wpdb->posts WHERE ID = %d”, 2)); Second the $wpdb->query will returns an integer value indicating the number of rows affected/selected. You can check here http://codex.wordpress.org/Class_Reference/wpdb#General_Syntax If you want generic result you can use $wpdb->get_results http://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results $mypost = $wpdb->get_results($wpdb->prepare(“SELECT post_content … Read more

Active DB queries in WordPress?

wpdb doesn’t include such kind of API, mostly since it descended from ezSQL which didn’t either (as far as I remember). While there are some helpers for insert/update stuff, most of query abstraction happens in WP_Query since that’s where bulk of complicated querying is typically going on.

Custom WordPress Table wpdb

First off, you should not be handing an untrusted input (in this case, $_GET[‘id’] to your database. Always SQL-escape the query and validate/sanitize the data. (In the code snippet below, it’s SQL-escaped using $wpdb->prepare() for escaping and int typecasting to sanitize to integer value). Secondly, the $wpdb object provides more than just the query() function. … Read more