How to connect to different Wordpress databases

Hi there!

I have various independent Wordpress websites installed on one server which all have the same custom post type. Now I would like to write a PHP program that imports data into these installations and populate this custom post type. This program is run every 60 seconds, checks whether there is a file in a specific directory and if yes, it imports data to one of the wordpress installations.

I implemented that program already and it works fine if I put it in one of the Wordpress sites and call it with the domain of that site. But this is a problem because I don't want to duplicate my import program and copy it to every site. I would rather have it in a separate location. Therefore my question: how can I tell my program to connect to a specific wordpress site?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
1. Wordpress sites all hosted on the same server then it is as simple as changing your DB connect properties for your program

2. If on different servers then as per 1 providing the hosting setup for each server allows remote access to the DB - otherwise you will have to write a proxy for each site to feed data back to the calling program.

I am assuming your program is written in PHP - is it a stand alone application or something you are plugging in to WP?
dirkil2Author Commented:
Thanks Julian for your answer. I think your solution does not work since my program is stand-alone and needs to call wordpress functions. It is called from the Windows scheduler by calling php.exe. Maybe if I do that then it's not possible since without an http request Wordpress might not know what to do.
Julian HansenCommented:
Not sure why you say it does not work - it was more a question than a solution.

a) your application can make HTTP requests to WP through the cUrl library
b) If your program is doing a simple DB connect then my original post stands.
If your sites are all on the same server then your program can switch between them by using different db connection parameters.
If your sites are on different servers - the ability to remote connect to the db's for those sites is dependent on whether the hosting platform allows remote access to the db - some do some don't.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dirkil2Author Commented:
Thank you for your idea of making HTTP requests myself. That might solve my problem. I might give that a go.
Julian HansenCommented:
You are welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.