• Resolved davidwilbourn

    (@davidwilbourn)


    I need to access some tables in the WP database from an external application so that I can add/edit events from a PC based application. The tables are not core-WP but ones created by a plugin.

    I can access a non-WP database (which is on the same server as the WP database) from within WP, MyPHPAdmin can access both the WP and non-WP database and my application can access the non-WP database, but I can’t access the WP database from the app. I get a MySQL error “Access denied to user”.

    Can anyone tell me if this is by design? Is WP deliberately preventing me from interfering with tables in it’s database or am I just missing something somewhere? Any suggestions would be gratefully received!

Viewing 5 replies - 1 through 5 (of 5 total)
  • @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.www.ads-software.com/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.

    Thread Starter davidwilbourn

    (@davidwilbourn)

    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.

    Thread Starter davidwilbourn

    (@davidwilbourn)

    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!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘External access to WP database’ is closed to new replies.