There is a class variable that stores the last error string – $wpdb->last_error. By the looks of the way $wpdb is coded, if the query succeeds, $wpdb->last_error will be an empty string, if it fails, it will be the error string returned by MySQL. So something like this would do the trick.
$result = $wpdb->get_results("SELECT * FROM this is not a valid query");
if ($wpdb->last_error) {
echo 'You done bad! ' . $wpdb->last_error;
}
Related Posts:
- Get error messages when $wpdb->insert() returns false?
- $wpdb->prepare() warning in WordPress 3.5
- What causes the “max_user_connections” warning on WordPress frontend?
- $wpdb variable throw this error Call to a member function get_results() on a non-object in
- $wpdb doesn’t like to store arrays
- Problem in using wpdb
- Using wpdb to connect to a separate database
- WPDB Insert or if exists Update
- get_results using wpdb
- $wpdb won’t insert NULL into table column
- How to fetch Data in WordPress using MySQLi or $wpdb
- wpdb->insert multiple record at once
- How to define composite keys with dbDelta()
- Does wpdb add considerable overhead on queries with large result sets?
- Hook into $wpdb
- Display data from a non wordpress database on a page template
- How does $wpdb handle COUNT(*)
- Changing the Database Connection Error Message
- WordPress database error: [Query was empty] [closed]
- Export wordpress table to excel
- When importing database, it shows error
- How to close wpdb connection? [duplicate]
- Connecting to external oracle database
- Strange Deadlock database error for the query “Delete From wp_options”
- Can’t save ajax value to database
- WordPress showing install screen after max_questions error
- Error establishing a database connection – with Debug Data
- How to execute mulitple statement SQL queries using $wpdb->query?
- When and why should I use $wpdb different return types?
- How wordpress accesses its own database
- Error connecting to DB in /wp-includes/wp-db.php on line 1538 [closed]
- How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?
- How to use a different database to list and manage comments in the backend
- Cannot update custom database table row
- wpdb_prepare with multiple or condition
- Show last modified date of database
- $wpdb->insert is not working
- Error establishing a database connection on Installation
- SQL Error wp_commentmeta – incorrect table definition
- Extracting the post_id via the wp_insert_post action (external db query)
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- In what part of the WordPress core does the users table and usermeta table get joined?
- Multiple wp_options tables to share content across installs
- Select two sums with single get_var statement
- Update from 4.5 to 4.6 failing
- WordPress running SQL query to update database from form
- How to fix database error duplicate entry
- $wpdb->insert Giving duplicates
- after wordpress update to 3.5+ i get many errors in plugin wpdb::prepare()
- WPDB SQL query with prepare() returning variable, not db value
- Moving to another server database connection error [closed]
- Have working sql query… trying to adjust it to use $wpdb
- $wpdb->query can’t insert data
- Custom WordPress Table wpdb
- Best practice to limit results in get_row()?
- Best practice to import user base (subscribers) from one website to another?
- AJAX wp-mysql running too slow
- CreateOrUpdate in WordPress
- Problem migrating to localhost
- Trouble running $wpdb->query() with last_insert_id
- How to get a list of WordPress default database tables?
- Using $wpdb | checking entered email against existing emails in db
- How to delete a particular row in a database table
- How to create more than one new wpdb object?
- Optimizing function that automatically creates internal links based on post title string
- Get results from wordpress data custom table
- Outputting query results
- WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version [closed]
- Getting value from database table depending on field value
- Creating and Using Tables in the WordPress Database
- wpdb->insert not inserting first variable
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- SELECT rows between two datetimes when the range is dynamic [closed]
- How to get the full stack trace for WordPress “table doesn’t exist” error in debug.log?
- How to insert a value to decimal type field using wpdb->prepare?
- SQL database import #1046 error
- Where is the HTML-handler part in the wpdb class?
- error establishing a database connection 3
- “wordpress error in establishing database connection” and missing tables
- error establishing database connection (WAMP + filezilla)
- How to add download link from database on custom page template?
- insert data from a form:: Warning Empty query mysqli::query()
- How can I get $wpdb to show MySQL warnings?
- Correct and secure way to access a custom SQL database in a custom PHP template file
- About wp database hooks (error establishing connection)
- How to get specific table by current user login
- Accessing content from third party as native posts in WordPress
- Hang Up Followed By Can’t select database
- Should I Use only wpdb Class to Write Custom Queries?
- Database error after importing WordPress
- Catchable fatal error in formatting.php
- using same mysql user with many databases
- Restoring .sql backup results in “Error establishing a database connection”
- How can I retrieve data from alternate database using wpdb class?
- Pulling values from a sepcific row in table
- Print output of Table Creation
- Insert Extra fields added in the front end registration form to DB
- How to delete field using WPDB?
- WordPress database error Unknown column
- Getting an error when trying to migrate to DV server from Grid with Media Temple [closed]