how does $wpdb differ to WP_Query?

The wpdb class is the interface with the database. WP_Query uses wpdb to query the database. You should use WP_Query when dealing with the native WordPress tables, to integrate your code properly with the WordPress environment. Use wpdb directly when you need to access data in your own tables.

$wpdb->prepare() warning in WordPress 3.5

Remove the call to $wpdb->prepare(): $result = $wpdb->get_var( “SELECT DISTINCT meta_value FROM $metatable WHERE meta_key LIKE ‘%matchme%’ AND meta_value IS NOT NULL AND meta_value <> ”” ); In this case, the $wpdb->prepare() function is not doing anything. There are no variables holding unknown values, therefore there is no need to sanitize them. If you did … Read more

$wpdb->last_error doesn’t show the query on error

If you want the query, that’ll be $wpdb->last_query (note that you also do not need SAVEQUERIES, that’s only if you want a log of every query ($wpdb->queries) last_error is… well, the error! Update: Possible explanation for last_error being empty – this is the source of wpdb::query(): // If we’re writing to the database, make sure … Read more

get_results on large datasets

$wpdb doesn’t suit for fetching huge amount of data from database. Why? In your case: $wpdb->get_results( … ) – fetches all results into your RAM at once. It means if you have 4mb, 10mb, or 50mb of data in db, everything will be stored in memory (what is limited as you know). $wpdb->get_results( …, ARRAY_A … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)