$wpdb object has some properties getting set for that:
// Print last SQL query string
// Print last SQL query result
// Print last SQL query Error
Note: First of all you have to set define( ‘SAVEQUERIES’, true ); in your wp-config.php file at root folder of WordPress.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.