@davidwilbour.,
I have one question, Do you need to access your non-wp tables in your WordPress source or an external source?
If its in wp you can access with global $wpdb variable
https://codex.wordpress.org/Class_Reference/wpdb
Any time yu get an “access denied” error, it’s because you’re using the wrong username/password for the MySL user set up for that database. What you’re seeing is an error from MySQL, not WordPress. You’ll need to check the user credentials that you’re using and see where they are not correct.
Catacaustic,
I thought it was the wrong user/password as well, but I can connect ok. The error only occurs when I execute an SQL statement. If I change the password or user to something obviously wrong I get the ‘access denied’ error immediately I try to open the connection so I think it has to be something different.
Rajan,
I can already access the non-WP tables, it’s the WP tables I can’t access from the external program.
As far as I know, opening the connection only connects to the server, it doesn’t actually test to see that the user has permissions over that database. The access denied error comes because the user doesn’t have permissions set for that database when you try to run the query. I’d double-check the permissions to check that the MySQL use that you’re using has the required permissions over the tables that you’re trying to query.
The way to find out is to run another query that’s about as generic as possible. Soemthing like:
SELECT * FROM wp_posts
Or even any of your own custom tables in that database. If you get an error, it would be permissions problems for that user. If you get a result, you’ll have a problem with the SQL statement in your initial query.
Solved!
Dumb beginner’s mistake: I had set the Access Host for the external database in DirectAdmin to my PC but had forgotten to do that for the WP database. Once I added that I had access to the WP database.
Sorry for having wasted anyone’s time. At least it might help the next newbie!