Value of prepared statement is listed as error in query string I have made a Wordpress plugin that writes some data to a proprietary table. 

The query as shown in the log is:

INSERT INTO berichten_devices (device_UUID, article_id) VALUES (%s, %s)


If I take this line and enter it manually via adminer in the database, replacing the first %s with 'test' and the second %s with 1:

INSERT INTO berichten_devices (device_UUID, article_id) VALUES ('test', 1)


The this is stored in the database without a problem. There is also another table that is written to from the plugin which works fine.

The php that is responsible for storing the data is as follows:

function insert_artice_read($uuid, $article_id) {
error_log('$uuid:'.$uuid, 0);
error_log('$article_id:'.$article_id, 0);

    $query = "INSERT INTO berichten_devices (device_UUID, article_id) VALUES (%s, %s)";
error_log('$query', 0);
error_log($query, 0);
    $query = $this-&gt;wpdb-&gt;prepare($uuid, $article_id);
    return $this-&gt;wpdb-&gt;query($query);
  }


The parameter $this->wpdb is defined as 

$this-&gt;wpdb = $wpdb;


The logging that is shown is this:

dcr-wordpress | [Tue Jun 25 10:45:03.363771 2019] [php7:notice] [pid 1953] [client 192.168.224.1:43584] $uuid:ABCDEF01-2345-6789-ABCD-9876543210AA
dcr-wordpress | [Tue Jun 25 10:45:03.363776 2019] [php7:notice] [pid 1953] [client 192.168.224.1:43584] $article_id:1
dcr-wordpress | [Tue Jun 25 10:45:03.363781 2019] [php7:notice] [pid 1953] [client 192.168.224.1:43584] $query
dcr-wordpress | [Tue Jun 25 10:45:03.363785 2019] [php7:notice] [pid 1953] [client 192.168.224.1:43584] INSERT INTO berichten_devices (device_UUID, article_id) VALUES (%s, %s)
dcr-wordpress | [Tue Jun 25 10:45:03.364844 2019] [php7:notice] [pid 1953] [client 192.168.224.1:43584] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ABCDEF01-2345-6789-ABCD-9876543210AA' at line 1 bij query ABCDEF01-2345-6789-ABCD-9876543210AA gemaakt door require('wp-blog-header.php'), wp, WP-&gt;main, WP-&gt;parse_request, do_action_ref_array('parse_request'), WP_Hook-&gt;do_action, WP_Hook-&gt;apply_filters, rest_api_loaded, WP_REST_Server-&gt;serve_request, WP_REST_Server-&gt;dispatch, Prop\\Inc\\Core\\RestController-&gt;article_retrieved, Prop\\Inc\\Common\\Repository-&gt;insert_artice_read
dcr-wordpress | 192.168.224.1 - - [25/Jun/2019:10:45:03 +0000] "POST /wp/wp-json/prop/v1/berichten-devices HTTP/1.1" 200 802 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"


From this logging it is obvious that there is something wrong with the sql syntax, but this line seems weird to me:

for the right syntax to use near 'ABCDEF01-2345-6789-ABCD-9876543210AA'


This is data from the prepared statement parameters, I would expect to see  something like

for the right syntax to use near %s


I tried to use %i instead of %s for the second parameter, just be sure, but there was no difference.

This is the table definition:

CREATE TABLE IF NOT EXISTS berichten_devices (
  device_UUID     VARCHAR(255) NOT NULL,
  article_id      int(10)      NOT NULL,
  date            timestamp(4) NOT NULL DEFAULT CURRENT_TIMESTAMP(4),

  KEY `dev_uuid` (device_UUID)


My question is basically: "What am I doing wrong?"
You likely will need to enclose the parameters in quotation marks if they are strings. Try this:

$query = "INSERT INTO berichten_devices (device_UUID, article_id) VALUES (\'%s\', \'%s\')";