wpdb->insert not working

I got the same problem. Solution 1: Strip your data.. WordPress rejects the query if the length of value is greater than the field length defined on the database. On your insert query, the value for post_type field exceeded the 20 character limit. Solution 2: Use the $wpdb->query method

Change post status based on meta value

Your code looks okay, and considering you are not submitting user entered data, the prepare() method isn’t required, but as a matter of best-practice it’s good to learn how it works and use it consistently. With that said, using the prepare() method, your code would look like this: $sql = $wpdb->prepare( ” SELECT ID FROM … Read more

Avoiding “Usage of a direct database call is discouraged”

Using $wpdb->insert and or related methods to modify data within any of the default WordPress tables, be it posts, postmeta, user, usermeta etc is discouraged because there are functions which already exist for the purpose of modififying data within those tables. For example, wp_insert_post wp_update_post wp_delete_post Database Queries Avoid touching the database directly. If there … 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

Matching database content types to PHP types

There is no way to automatically make wpdb do this. This is really a limitation of PHP that WordPress doesn’t happen to address. wpdb doesn’t have any hooks or actions that would help you either, so the best thing you can do is write your own wrapper function and run your queries through that so … Read more

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