You should be using the wpdb
class for all your own queries. All core queries also use wpdb
. See wpdb
Show and Hide SQL Errors
<?php $wpdb->show_errors(); ?>
<?php $wpdb->hide_errors(); ?>
You can also print the error (if any) generated by the most recent query with print_error.
<?php $wpdb->print_error(); ?>
Also see SAVEQUERIES constant for wp-config.php
:
define('SAVEQUERIES', true);
usage example:
<?php
if (current_user_can('administrator')){
global $wpdb;
echo "<pre>";
print_r($wpdb->queries);
echo "</pre>";
}
?>
There are also a number of helpful debugging plugins, like Debug Bar & Console. Search the WordPress plugin repository for this and other debugging related plugins.
Related Posts:
- #1115 – Unknown character set: ‘utf8mb4’
- Error: MySQL shutdown unexpectedly. XAMPP local conf running WordPress
- How can I make wordpress suppress mysql errors?
- #1115 – Unknown character set: ‘utf8mb4’
- Regarding “Insert query error” in wordpress
- Error missing MySQL extension
- Migration problems with mysql: Operation not allowed when innodb_forced_recovery > 0 [closed]
- Why can’t i come back to older working version of php after ugrade with error log on php 7.2 and 7.3
- #1115 – Unknown character set: ‘utf8mb4’
- Datatabase error: Commands out of sync
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
- Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’ (38)
- ERROR 1698 (28000): Access denied for user ‘root’@’localhost’
- ERROR 1698 (28000): Access denied for user ‘root’@’localhost’
- When to use SELECT … FOR UPDATE?
- ERROR 1396 (HY000): Operation CREATE USER failed for ‘jack’@’localhost’
- Database sharding vs partitioning
- Getting “Lock wait timeout exceeded; try restarting transaction” even though I’m not using a transaction
- Search for all occurrences of a string in a mysql database
- how to overcome ERROR 1045 (28000): Access denied for user ‘ODBC’@’localhost’ (using password: NO) permanently
- #1045 – Access denied for user ‘root’@’localhost’ (using password: YES)
- How to convert a string to date in MySQL?
- MySQL COUNT DISTINCT
- How to update a record using sequelize for node?
- Fatal error: Please read “Security” section of the manual to find out how to run mysqld as root
- Can’t open the mysql.plugin table. Please run mysql_upgrade to create it
- Convert MySQL to SQlite [closed]
- Create a temporary table in a SELECT statement without a separate CREATE TABLE
- Convert partially non-numeric text into number in MySQL query
- MySql: is it possible to ‘SUM IF’ or to ‘COUNT IF’?
- MySQL: What’s the difference between float and double?
- How can I search (case-insensitive) in a column using LIKE wildcard?
- MySQL Select Multiple VALUES
- SQL – IF EXISTS UPDATE ELSE INSERT INTO
- How to unblock with mysqladmin flush hosts
- Node.js MySQL – Error: connect ECONNREFUSED
- Solution to “subquery returns more than 1 row” error
- MySQL Error #1071 – Specified key was too long; max key length is 767 bytes
- How To have Dynamic SQL in MySQL Stored Procedure
- MySQL – UPDATE query with LIMIT
- MySQL said: Documentation #1045 – Access denied for user ‘root’@’localhost’ (using password: NO)
- What SQL Query to do a simple find and replace
- Alternative to mysql_real_escape_string
- Increment value (value = value+1) of $wpdb->update
- SQL query not working in alphabetical post title/content search
- Same option_id=0 for 2 options in wp_options?
- How to let a user choose an authors and save it to the database?
- How to remove ‘GROUP BY’ from SQL query produced from get_posts?
- MySQL LIKE not working
- Is a MySQL DATETIME or TIMESTAMP value retrieved through $wpdb in UTC?
- Join new table with SQL query
- WordPress installation on valet php 8 (PHP Fatal error: Uncaught mysqli_sql_exception Table ‘wp_options’ doesn’t exist in wp-includes/wp-db.php:2056)
- MySQL crashed because of the large number of requests
- Why doesn’t this code add a table to my database?
- SQL database export-import
- Can Someone Help Me Fix This WordPress Missing Argument Error?
- How do I get create a custom table showing the hours remaining for all customers in one page from this transactions page?
- Uncaught Error: Call to undefined function mysql_connect() – WordPress installation
- SQL Database, repeated tables?
- Visual/Text Editor displays blank pages in WP-Admin- but HTML on client side displays correctly
- Code to remove authors with no posts connected to them
- SQL Query in WordPress – Getting Impossible WHERE error
- WordPress create database not working
- Import CSV to MySQL, with custom registration field information
- database optimization and server errors
- Setting up WordPress Locally on WAMP for a new site (with one already)
- Calling mysql_query() on another database, assumes WordPress using that database
- WordPress VIP realpath Alternative?
- querying user bookmarks from a large number of bookmarks
- Pull post name from value of a specific meta key
- PHP variables in mysql query
- How to fix the amount of comments displayed for each post?
- How do I echo all users’ display_name and their meta_value who have a certain meta_key?
- PHP Warning: mysqli_query(): after updating my websites php from 5.6 to 7.2
- How to simulate web traffic to test performance of a website
- WordPress Bad Request Error 400
- SQL query to change custom field in WordPress database
- SQL. Select category descendants
- What is the MYSQL Query to bulk update the canonical URL of specific categories of posts in WordPress?
- MySQL Actibity without any active visitors via Google Analytics
- How to configure WordPress Database for CentOS 7
- Why is local wordpress install calling live site executions?
- Add row to SQL array
- Display MySQL as part of a Page
- Hang Up Followed By Can’t select database
- Migration of wordpress database from mariadb 10.0.20 to 5.5.50
- Use custom query if main search query returns zero results in wordpress
- WP Meta Query – mixed AND / OR query doesn’t work
- Second completely independent and disposable WordPress installation in subdirectory?
- get_results suddenly not working on a single table
- Internal error (500) on local & Fatal error on live when trying to access post type edit screen
- Query sql for truncate post_content in wp_posts table
- Foreach only outputs if id is 0
- Using queries in and i see 7000+queries?
- “Error 1064” when importing msql database after updating wordpress version to 4.2.1
- remove wordpress post links
- SQL get last entry of a specific gravity form
- mysqldump to a tar.gz
- Where is my mysql log on OS X?