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

Why line returns are not reapply after doing esc_sql?

That’s not what esc_sql is for, or what it should be used for. Safely Escaping Variables In SQL Queries To make variables safe for an SQL query, use $wpdb->prepare, e.g. $table_name = “{$wpdb->prefix}myTable”; $myID = 12; $wpdb->query( $wpdb->prepare( “UPDATE `$table_name` SET `your_column_1` = 1 WHERE `$table_name`.`your_column_id` = %d”, $myID ) ); Notice that $myID is … Read more

Sql formatting for post data within function

It isn’t showing wp_posts.post_content LIKE ‘%test%’ because the wildcards (%) in the prepared statement are converted to placeholder escape strings (like the {a19f0a6c3d866f7270be0f3954cbb2600270400c15f488e112449a8a131701f0} in your post) when wpdb::prepare() calls wpdb::add_placeholder_escape() which “Adds a placeholder escape string, to escape anything that resembles a printf() placeholder“, i.e. a placeholder like %s. But those placeholder escape strings will … Read more

How to left join meta in queries [closed]

One possible solutions is use Queries in the joins instead of tables. so the query would look something like //read products with thumbnail and sku SELECT products.*, skus.sku, thumbs.thumbnail FROM `wp_posts` as products LEFT JOIN ( SELECT posts2.ID, pm1.meta_value as sku FROM `wp_posts` as posts2 LEFT JOIN `sf_postmeta` as pm1 ON posts2.ID = pm1.post_id WHERE … Read more

dynamic page using php from sql database

I managed to fix this myself with the following <?php if (isset($_GET[‘id’])) { $id = $_GET [‘id’]; } else { $id = “”; } //$url = “http://18.168.90.222/device-repair-service/device?id=$id”; require ‘sql_connect.php’; try { $connection = new PDO($dsn, $username, $password); $connection -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //echo “connection succesful”; } catch (PDOException $error){ echo $error -> getMessage(); } //prevent SQL … Read more

Removing posts by sql

You’re probably better off doing this with wordpress functions and adding a button which would delete all posts (or even having a shortcode that, when loaded, would do it). The reason I recommend doing this instead of SQL directly is that wp_delete_post() will take all the associated meta with it, which saves you having to … Read more