Don’t use $wpdb->prepare
with table names. prepare
will quote your table names that will result in incorrect SQL.
It is unnecessary overhead as well. Your table name should never, and in your case isn’t, be user-supplied data. You have no need to escape it. ‘prepare’ is for use on user-supplied data, such as data from a form or a $_GET
parameter.
You have no user-supplied data so all you need is
$wpdb->get_results("SELECT * FROM {$tablename}");
Related Posts:
- Retrieving custom fields with $wpdb->get_results
- SQL query for custom taxonomy slugs
- How to optimize multiple insert into wordpress database
- How to store sensitive user data (passwords)
- I can’t write in my DB using $wpdb->insert
- Should I use wpdb prepare?
- Is it mandatory to use $wpdb->prefix in custom tables
- $wpdb->insert_id
- Check for success of $wpdb->update() correctly
- Getting wrong relationship value in $args in wp_Query?
- WordPress and multithreading
- $wpdb->insert is changing a value
- Actions or filters fired when data is saved in a custom table
- Display only certain posts based on visitor’s country?
- Custom Plugin Database relations
- why creating tables using $wpdb is not being executed while installing plugins?
- How to use mysql IN statement with wpdb update method?
- How to add SQL file with PHP to WordPress database [closed]
- Using $wpdb object in a widget
- Activation hook not creating table
- $wpdb -> Batch insert from XML File?
- How to Download and install plugin database remotely
- How to insert data to a database table when the field is not yet created?
- Where to store the name of a custom table?
- include wp-blog-header not working on MAMP
- creating custom function to log actions in plugin
- Issue regarding $wpdb->prepare()
- Error on inserting a form value to database
- How to create database table, add data, update and delete using wpdb via plugins?
- Using WPDB to output raw XML fails because of wp-blog-header.php
- how to search users by ajax live search
- Adding custom end points, No error line
- Intermittent database errors when accessing WordPress database
- Storing data in wordpress database from ajax call from different website
- wpdb->prepare and mysql UPDATE – how is it done?
- $wpdb->prepare with LIKE and sprintf
- $wpdb->update() always need a second try
- Using AND and bracket grouping in SQL not working
- Data inserted by wpdb insert is different than data pressnt in database.
- Proper Prepare Statement for ALTER TABLE and using AFTER
- wpdb->get_var always returning 0
- $wpdb->prepare is not working like mysql_real_escape_string
- How to avoid conflicts with db.php / $wpdb and other plugins that decide to use them?
- $wpdb in php 5.5
- Plugin to create Posts and Forums then choose category and parent forum
- $wpdb->update Issue
- How to relate the Category to user?
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- Why doesn’t my Table get created?
- How to display specific data from a custom table to logged in users with a custom role
- $wpbd->insert_id is returning null
- How to get inserted row IDs for bulk/batch insert with wpdb query?
- WordPress Query doesn’t return the correct value
- User avatar-ACF fields
- bindParam? WordPress 4.9.5 SQL LIKE statement %s and %LIKE%
- Update database record in plugin
- Organising and completing posts (mark as read and hide)
- Dedicated server and WPDB Class : huge slow-down of the website
- How to implement pagination into a wpdb->result query?
- How to CRUD from wordpress database in wordpress theme?
- $wpdb how can i save my postmeta table before querying it
- How to add chunk of php, html, and sql code to variable an append to $content
- WordPress plugin tables become corrupt
- Nothing happens on WordPress Update command
- Fixing plugin for wpdb::prepare
- Get all the related data from WordPress DB
- select rows based on exact time (hours, minutes and seconds)
- multiple record insert creating many duplicate records
- How to properly prepare a column name if passed to a stored procedure?
- Plugin architecture to pull from API & create dynamic content on WP site?
- Undefined is_user_logged_in() error with Plugin Query code
- Add code to template dynamically
- Thickbox in Plugin settings page?
- Plugin Options not saving options and doesn’t work
- How to localize data array in plugin’s option page
- Plugin admin page stylesheet doesn’t work
- How To Protect Plugin Display From Being Affected By Theme’s CSS
- How to remove/replace current page template?
- WordPress dynamic widget by location?
- wp login redirect loop reauth=1
- How do I add a menu item to a Pods admin menu?
- How to share user data across multiple WordPress websites?
- sanitizing/escaping plugin options
- Bootstrap Error in WordPress plugin
- Update plugin settings option_name for big plugin update
- Getting value from database table depending on field value
- Load stylesheet in edit category page?
- how to get the top 10 popular blogs
- What could cause a WP Option to get truncated?
- select a single val though a table in wordpress
- wpdb prepare sql problem
- Checking for existing title in custom db query not working
- Borrowing of Previously Translated Strings by Child Plugin
- Enqueue scripts inside a class in a plugin
- Adding filter to the title without affecting the menu title
- How do I query for posts by custom meta and those that have been stickied?
- Redirect User to custom URL after registering
- Load php file with jquery in single.php
- How can I change my assigned user role in WordPress 3.5.1?
- Listing wordpress users with a search function