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

Custom search Dashboard widget

Firstly, let’s start off by cleaning up the query you have above. I’ve put it into Heredoc syntax to make it easier to read. $sql = <<<SQL SELECT * FROM {$tablename} — you should use interpolation when working in a string that can have variables WHERE ( — Your query will only ever match one … 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

Does WordPress have something like Drupal’s DB API?

Yes, there’s the wpdb class. Some examples can be found for e.g. here. Then there’s the global $wpdb object that contains results and other parts, set based on the current routing. You can also utilize the WP_Query class which is more common. There’s a default global $wp_query object and the $wp_the_query(?) intermediary object, that holds … Read more

CreateOrUpdate in WordPress

If I’m not too badly mistaken, I don’t think there’s a similar method in $wpdb. replace, https://developer.wordpress.org/reference/classes/wpdb/#replace-row, is kind of like that, but not quite as sophisticated I believe. You probably need to build a helper function for that yourself, which wraps update, insert and a bit of logic together. Or use query method with … 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

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