How to prepare an array of values with $wpdb

Not quite there. In your first example you have sku LIKE %s and in your example you have product_sku LIKE ‘%{$matchedProduct->sku}%’. That’s not the same. $wpdb->prepare() uses sprintf replacements. That’s where you get the %s in your first query. If you look at the sprintf documentation under specifiers, you’ll find a list of replacement patterns. … Read more

WordPress “wpdb->update” – Append Text Value

Short answer: it’s not possible. Long answer: you should try $wpdb->query instead and write a regular SQL query, something like this: UPDATE table_name SET notes = CONCAT(notes, ‘text to append’) WHERE note_id = ‘313’ Please note it’s only an example and you should use $wpdb->prepare to also sanitize variables properly.

Save data from a checkbox to a wpdb array

This isn’t a WordPress question this is a PHP question. Your foreach loops through all the $checkboxes putting one in the $check variable each time, so your insert() call only inserts the last value for $check, because it’s not inside that foreach loop. You probably want: global $wpdb; foreach( $checkboxes as $check ) { $wpdb->insert(‘data’,array(‘fruit’ … Read more

CREATE TABLE with dbDelta does not create table

Found a couple of things and am including what I believe will work to correct your issue. (As an aside, you should try and simplify your initial attempts so you can isolate what works and what doesn’t. This is really complex for an initial attempt.) One thing, you’ll struggle to have a field named timestamp, … Read more

get_results query with accent

Your SQL command is highly insecure and open to security issues like SQL injection, so even if this may not answer the question, I strongly suggest you to use $wpdb->prepare() and $wpdb->esc_like() — the latter is used to escape the % character in SQL. Additionally, you can simply use $wpdb->posts to output the table name … Read more

Set MySQL variables in WPDB

I am so silly. With this in the end, I set a PHP variable that I needed instead of the “@SET”. My final code was this: $group_sql = “SELECT product_group FROM insert_temporary LIMIT 1”; $group = $wpdb->get_var($group_sql); $sql = “SELECT * FROM insert_temporary WHERE product_group in (SELECT product_group FROM insert_temporary WHERE product_group = ‘”. $group … Read more

wpdb->get_row is selecting the variable as a column name

The error in question happened because you did not properly build your SQL query/statement: The column name in your query is hashcode, and you are trying to get the row where the column value matches the value of the $file_hash variable, i.e. WHERE {$file_hash} = `hashcode`. But because the value is a string/text (and not … Read more

Trying to get variable from WP table and toggle its value

There are two issues I see in your code: The $searchIP is actually outside of the $wpdb->prepare(): (I didn’t use the full query so that you’d see the issue clearer) $StatusCheck = $wpdb->get_var( $wpdb->prepare(“SELECT payment_status …”),$searchIP); So you should correct that, like so: (reindented for clarity) $StatusCheck = $wpdb->get_var( $wpdb->prepare( ” SELECT payment_status FROM {$ipn_tables} … Read more

How to protect a script execution on WordPress?

One approach (avoiding PHP timeouts) for a local Linux Cron Job (for exact timing) is creating a WP-CLI command (does not run in the browser), like: <?php /* Plugin Name: WP-CLI Foo */ function foo_command( $args ) { // Adjust to your needs … WP_CLI::success( $args[0] ); } WP_CLI::add_command( ‘foo’, ‘foo_command’ ); and the corresponding … Read more

$wpdb->prepare was called incorrectly when inserting multiple records

Well, you don’t need the second $wpdb->prepare() and just do $wpdb->query( $query );. The reason is because the $query does not contain any placeholders just as stated in the notice; only the items in $values contain the placeholders, but you already prepared them in the foreach. Additionally, be sure to run the query() only if … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)