Title: WP Data Access Table Doesn&#8217;t Exist
Last modified: April 29, 2024

---

# WP Data Access Table Doesn’t Exist

 *  Resolved [mary7678](https://wordpress.org/support/users/mary7678/)
 * (@mary7678)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/)
 * Hello!
 * I’m working on coding a custom plugin which needs to query data from a simple
   table I created via WP Data Access using CSV upload. When I query the WordPress
   database, I receive the following error:
 * WordPress database error Table ‘lthshuya_wp893.productlookup’ doesn’t exist for
   query SELECT * FROM productlookup WHERE competitor_brand = ‘Hu Friedy’ AND competitor_part
   LIKE ‘%678-210%’
 * The database is lthshuya_wp224, but when I tried putting that before the table
   name, I got this error:
 * WordPress database error SELECT command denied to user ‘lthshuya_wp893’@’localhost’
   for table `lthshuya_wp224`.`productlookup` for query SELECT nordent_part FROM
   lthshuya_wp224.productlookup WHERE competitor_brand = ‘Hu Friedy’ AND competitor_part
   LIKE ‘%678-210%’
 * I used the global $wpdb; to access the database so I’m not sure why there would
   be a permissions error. Could you please provide some direction as to how I can
   query the productlookup table?
 * Thank you!!!
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fwp-data-access-table-doesnt-exist%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 14 replies - 1 through 14 (of 14 total)

 *  Plugin Contributor [Kim L](https://wordpress.org/support/users/kimmyx/)
 * (@kimmyx)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17720397)
 * Hi [@mary7678](https://wordpress.org/support/users/mary7678/),
 * Thanks for posting and we’re sorry to hear you encountered issues with accessing
   your database.
 * Is `lthshuya_wp224` accessible for your user in **WP Data Access** > **Data Explorer**?
 * A sample of how you can query a table via PHP is outlined here: [Remote database access | WP Data Access](https://wpdataaccess.com/docs/api/remote-database-access/)
 * You can also send us a message at [Contact | WP Data Access](https://wpdataaccess.com/contact/)
   if you want to share more information privately.
 * We’ll wait for your response!
 *  Thread Starter [mary7678](https://wordpress.org/support/users/mary7678/)
 * (@mary7678)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17722268)
 * Yes, I can access and manage lthshuya_wp224 and the productlookup table I created
   from the WP admin section just fine. The issue is that my PHP code doesn’t seem
   to want to recognize that table.
 * This is the code I had been using:
 *     ```wp-block-code
       	global $wpdb;
       	$query = "SELECT nordent_part FROM productlookup WHERE competitor_brand = '" . $name . "' AND competitor_part LIKE '%" . $part . "%'";
       	$results = $wpdb->get_results( $query );
       ```
   
 * Based on the example you sent, I replaced it with the following:
 *     ```wp-block-code
       $wpdadb = WPDataAccess\Connection\WPDADB::get_db_connection( $wpdb );
       	$query = "SELECT nordent_part FROM productlookup WHERE competitor_brand = '" . $name . "' AND competitor_part LIKE '%" . $part . "%'";
       	$results = $wpdadb->get_results( $query );
       ```
   
 * Which then resulted in this error:
 *     ```wp-block-code
       [30-Apr-2024 00:50:05 UTC] PHP Fatal error:  Uncaught Error: Class 'WPDataAccess\Connection\WPDADB' not found in /home/lthshuya/dev.maryschieferstein.com/test-site/wp-content/plugins/nordent-product-lookup-tool/core/includes/nordent-product-lookup-tool-action.php:20
       Stack trace:
       #0 {main}
         thrown in /home/lthshuya/dev.maryschieferstein.com/test-site/wp-content/plugins/nordent-product-lookup-tool/core/includes/nordent-product-lookup-tool-action.php on line 20
       ```
   
 * Can you please tell me what I need to do to connect properly so that I can access
   the table? I didn’t expect to run into this error, and apparently my client needs
   this working this week.
 *  Plugin Contributor [Kim L](https://wordpress.org/support/users/kimmyx/)
 * (@kimmyx)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17723268)
 * Hi [@mary7678](https://wordpress.org/support/users/mary7678/),
 * Thanks for the response.
 * Could you try the following instead?
 *     ```wp-block-code
       $wpdadb = WPDataAccess\Connection\WPDADB::get_db_connection('lthshuya_wp224');
       	$query = "SELECT nordent_part FROM productlookup WHERE competitor_brand = '" . $name . "' AND competitor_part LIKE '%" . $part . "%'";
       	$results = $wpdadb->get_results( $query );
       ```
   
 * Let us know if that works. 🙏
 *  Thread Starter [mary7678](https://wordpress.org/support/users/mary7678/)
 * (@mary7678)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17723764)
 * No, it gives the same error that it doesn’t have the ‘WPDataAccess\Connection\
   WPDADB’ class. Is there a file I need to include in order to get that class? 
   This is in a subfolder of a plugin, so it seems that things aren’t being included
   automatically.
 * Would it be more helpful if I could give you access to take a look?
 *  Plugin Contributor [Kim L](https://wordpress.org/support/users/kimmyx/)
 * (@kimmyx)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17725378)
 * Hi [@mary7678](https://wordpress.org/support/users/mary7678/),
 * Thanks for the response.
 * It might just be a matter of a missing backslash according to Peter.
 * Instead if writing this:
   `$wpdadb = WPDataAccess\Connection\WPDADB::get_db_connection('
   lthshuya_wp224');`
 * Please try:
   `$wpdadb = \WPDataAccess\Connection\WPDADB::get_db_connection('lthshuya_wp224');`
 * It depends on from where this code is called.
 * Let us know how it goes. 🙏
 *  Thread Starter [mary7678](https://wordpress.org/support/users/mary7678/)
 * (@mary7678)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17725783)
 * I updated the line to:
 *     ```wp-block-code
       $wpdadb = \WPDataAccess\Connection\WPDADB::get_db_connection('lthshuya_wp224');
       ```
   
 * And got the same error:
 *     ```wp-block-code
       [01-May-2024 10:19:20 UTC] PHP Fatal error:  Uncaught Error: Class 'WPDataAccess\Connection\WPDADB' not found in /home/lthshuya/dev.maryschieferstein.com/test-site/wp-content/plugins/nordent-product-lookup-tool/core/includes/nordent-product-lookup-tool-action.php:20
       Stack trace:
       #0 {main}
         thrown in /home/lthshuya/dev.maryschieferstein.com/test-site/wp-content/plugins/nordent-product-lookup-tool/core/includes/nordent-product-lookup-tool-action.php on line 20
       ```
   
 * My client needs this plugin working this week, and there’s more I’ll have to 
   do once I get the database connection working. I’ve used WP Data Access previously
   and was able to query tables via $wpdb, so I wasn’t expecting to run into all
   these problems. Is there any way we could troubleshoot this more quickly?
 *  Plugin Author [Passionate Programmer Peter](https://wordpress.org/support/users/peterschulznl/)
 * (@peterschulznl)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17725856)
 * Hi [@mary7678](https://wordpress.org/support/users/mary7678/)
 * Just checking: Is WP Data Access installed and activated?
 * Thanks,
   Peter
 *  Thread Starter [mary7678](https://wordpress.org/support/users/mary7678/)
 * (@mary7678)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17725892)
 * Yes, it is.
 * I managed to get past some of the errors by including these files:
 *     ```wp-block-code
       	require_once('../../../wp-data-access/WPDataAccess/Connection/WPDADB.php');
       	require_once('../../../wp-data-access/WPDataAccess/Data_Dictionary/WPDA_Dictionary_Exist.php');
       ```
   
 * Now I’m back to getting the following error:
 *     ```wp-block-code
       [01-May-2024 10:44:08 UTC] WordPress database error SELECT command denied to user 'lthshuya_wp893'@'localhost' for table lthshuya_wp224.productlookup for query SELECT nordent_part FROM lthshuya_wp224.productlookup WHERE competitor_brand = 'Hu Friedy' AND competitor_part LIKE '%678-210%';
       ```
   
 * It seems that it’s connecting to the database with a different user than the 
   one defined in wp-config.php. Is there a way to edit the WPDADB connection to
   fix that?
 *  Plugin Author [Passionate Programmer Peter](https://wordpress.org/support/users/peterschulznl/)
 * (@peterschulznl)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17725938)
 * Hi [@mary7678](https://wordpress.org/support/users/mary7678/)
 * It looks like your lookup table is stored in another database (= not your WordPress
   database) and your WordPress user has no access to that table. You have two options
   to fix this:
 * (1) Create a remote connection and connect as the owner
   (2) Give your WordPress
   user select access to the table
 * BTW, importing WP Data Access files should not be necessary. Please fix this 
   code before your continue:
   $wpdadb = \WPDataAccess\Connection\WPDADB::get_db_connection(‘
   lthshuya_wp224’);
 * For this code to work you have to wait until all plugins are loaded! (see hook:
   plugins_loaded)
 * Hope this helps,
   Peter
 *  Thread Starter [mary7678](https://wordpress.org/support/users/mary7678/)
 * (@mary7678)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17725943)
 * The WordPress user defined in the config file is lthshuya_wp224, not lthshuya_wp893,
   so it’s connecting to the database with the wrong user. If I can switch it to
   lthshuya_wp224 it should work.
 * The table is set up within the WordPress database:
 * ![](https://i0.wp.com/dev.maryschieferstein.com/test-site/wp-content/plugins/
   nordent-product-lookup-tool/core/includes/assets/Screenshot%202024-04-29%20at%
   2001.03.48.png?ssl=1)
 *  Thread Starter [mary7678](https://wordpress.org/support/users/mary7678/)
 * (@mary7678)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17726061)
 * If I set up a new wpdb object with explicit connection information, it runs the
   query:
 *     ```wp-block-code
       $wpdb_npl = new wpdb(/* connection information here */);
       	$query = "SELECT nordent_part FROM productlookup WHERE competitor_brand = '" . $name . "' AND competitor_part LIKE '%" . $part . "%';";
       	$results = $wpdb_npl->get_results( $query );
       ```
   
 * But $results seems to always be empty. When I run the same query in WP Data Access’
   SQL interface, I get a result. Is that because it has to be set up as a WPDADB
   object?
 *  Plugin Author [Passionate Programmer Peter](https://wordpress.org/support/users/peterschulznl/)
 * (@peterschulznl)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17726401)
 * If your table is stored in your WordPress database, you don’t need the WPDBA 
   class. In that case you can use $wpdb to connect. Your initial code should work:
 *     ```wp-block-code
       global $wpdb;
       $query = "SELECT nordent_part FROM productlookup WHERE competitor_brand = '" . $name . "' AND competitor_part LIKE '%" . $part . "%'";
       $results = $wpdb->get_results( $query );
       ```
   
 * You only need WPDADB to connect to remote and local non WordPress databases.
 * If you get an access denied error, this is probably an authorization issue. To
   fix it, make sure your WordPress user is allowed to access your table.
 * Does this help?
 *  Thread Starter [mary7678](https://wordpress.org/support/users/mary7678/)
 * (@mary7678)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17727204)
 * I finally figured out the issue. I set up my test WordPress site in a subdirectory
   of another WordPress site. No matter what I did, the database connection kept
   trying to use the information for the site in the main directory rather than 
   for the one in the subdirectory. I set up a new test site at its own subdomain
   and then everything worked. Never would have expected that to cause an issue,
   especially when I was pulling in the correct wp-config information.
 * Thank you so, so much for all your help!!! Sorry it turned out to be a weird,
   unrelated problem.
    -  This reply was modified 1 year, 11 months ago by [mary7678](https://wordpress.org/support/users/mary7678/).
 *  Plugin Contributor [Kim L](https://wordpress.org/support/users/kimmyx/)
 * (@kimmyx)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17727916)
 * Hi [@mary7678](https://wordpress.org/support/users/mary7678/),
 * We’re glad to know you were able to find out the root cause of the issue eventually.
   😊
 * Feel free to create a thread or send us a message if you have new questions.

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘WP Data Access Table Doesn’t Exist’ is closed to new replies.

 * ![](https://ps.w.org/wp-data-access/assets/icon-256x256.png?rev=3299063)
 * [WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards](https://wordpress.org/plugins/wp-data-access/)
 * [Support Threads](https://wordpress.org/support/plugin/wp-data-access/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-data-access/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-data-access/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-data-access/reviews/)

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [exist](https://wordpress.org/support/topic-tag/exist/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [table](https://wordpress.org/support/topic-tag/table/)

 * 14 replies
 * 3 participants
 * Last reply from: [Kim L](https://wordpress.org/support/users/kimmyx/)
 * Last activity: [1 year, 11 months ago](https://wordpress.org/support/topic/wp-data-access-table-doesnt-exist/#post-17727916)
 * Status: resolved