How do you properly prepare a %LIKE% SQL statement?

The $wpdb->esc_like function exists in WordPress because the regular database escaping does not escape % and _ characters. This means you can add them in your arguments to wpdb::prepare() without problem. This is also what I see in the core WordPress code: $wpdb->prepare(” AND $wpdb->usermeta.meta_key = ‘{$wpdb->prefix}capabilities’ AND $wpdb->usermeta.meta_value LIKE %s”, ‘%’ . $this->role . … Read more

MySQL said: Documentation #1045 – Access denied for user ‘root’@’localhost’ (using password: NO)

I installed xampp,but when I tried to run it I got an error as thus: Error MySQL said: Documentation 1045 – Access denied for user ‘root’@’localhost’ (using password: NO) Connection for controluser as defined in your configuration failed. phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check … Read more

Error: Duplicate entry ‘0’ for key ‘PRIMARY’

For those arriving at this question because of the question title (as I did), this solved my problem: This error can indicate that the table’s PRIMARY KEY is not set to AUTO-INCREMENT, (and your insert query did not specify an ID value). To resolve: Check that there is a PRIMARY KEY set on your table, and that the … Read more

Failed to Connect to MySQL at localhost:3306 with user root

8 I use Mysql Workbench to connect my database,[ Hostname Port and Username are as shown in figure ,and password is right.When I click Test Connection ,it show as above.But if i use 3307 in place of 3306 as port,it connect sucessfully. What matter lead that and how I fix it? I use macbook pro … Read more

GROUP_CONCAT comma separator – MySQL

I have a query where I am using GROUP_CONCAT and a custom separator as my results may contain commas: ‘—-‘ This all works well, however it is still comma separated, so my output is: How can I make it so the output is: I thought this was the idea of a custom separator! Failing that, … Read more

Is merge statement available in MySQL

MERGE is not supported by MySQL, However, there is other possible way of doing the same: INSERT…ON DUPLICATE KEY UPDATE If you specify the ON DUPLICATE KEY UPDATE option in the INSERT statement and the new row causes a duplicate value in the UNIQUE or PRIMARY KEY index, MySQL performs an update to the old row … Read more