-
-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proper and standard use of $wpdb->prepare #2442
Comments
If this is a custom table name, you can either pass it as a parameter to the "SELECT * FROM {$wpdb->prefix}_table_name WHERE..." the table name could be something like You'll still get the I'd recommend using native WooCommerce (from the looks of the DB query) functions to get information about the order like $order = wc_get_order( $order_id ); |
Hi @dingo-d, Thank you for your reply, As you can see I used
|
Take a look at this update. You can use this: $table_name = 'your_table_name';
$field = 'order_id';
$order_id = ''; // Your order ID.
$get_order = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM %i WHERE %i = %d", $table_name, $field, $order_id ) ); |
@dingo-d |
Hi,
Bug Description
I am developing a plugin and I use WordPress standard (Code Sniffer)
But I get the following standard error on this code
I need to know how can I use $wpdb->prepare in the following code to pass the standard?
Minimal Code Snippet
$get_order = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table_name} WHERE order_id = %d", $order_id ) );
I get this error:
Use placeholders and $wpdb->prepare(); found interpolated variable {$table_name} at "SELECT * FROM {$table_name} WHERE order_id = %d"
Could you please mention a standard way of using $wpdb->prepare containing a table name variable?
When I use table name as a place holder in $wpdb->prepare, I get another SQL error because it adds ' sign around the table name!!
Thank you for any help
The text was updated successfully, but these errors were encountered: