Wordpress connecting to a different MySQL database

Hi all,

I’m relatively confident this is possible but I would really appreciate some clarification from anyone with experience.

We have our blog running under Wordpress - we now have a separate web application utilising a different MySQL database and tables. What we like to do sounds simple. From within one of our wordpress pages I would like to access the different MySQL database and display information from that database on my wordpress page.

I would like to know:

  1. Is this possible and if so how?

  2. Will it affect my wordpress page and/or database connection

Thanks in advance everyone,

Homer J

I’d suggest setting up another wordpress blog that accesses these new tables, then setting up a redirect from that page, to the new blog page.

any links from the new blog page can then be redirected back to the old blog page.

You would have to duplicate the blog theme/layout etc so it matches though.

You might even be able to preserve the url path by adjusting the “general” settings too :slight_smile:

Hope this helps,

Dave

Possible? Yes.

Difficult? If you don’t know PHP, most definitely!

The way I’d approach this is to write a wordpress plugin that carries out what you want to do. This plugin would have it’s own config file with the information of that database in it.

Not entirely sure if it’s possible though, when it comes to select multiple DB’s (every DB connection requires you to select a DB before running MySQL queries). I know you can select it in MySQL, just not sure if the Wordpress class that runs the DB selection uses mysql_select_db or mysqli_select_db.

Hi Dave,

Thanks for the reply - any reason why you would recommend setting up another blog and tables for the other DB?

To elaborate - the other MySQL table is a client application and we just want to display information from one of those tables in our Wordpress page, it seems overkill to replicate everything for the sake of doing that?

Any further advice?

Thanks,

Homer.

I should have explained a little more - quite happy coding in PHP and MySQL so that isn’t a problem - however I am a Wordpress novice.

I know that I can drop code into Wordpress files - I guess I was interested in what the ‘best practice’ solution would be for what I want to do?

Interesting that you have mentioned about creating a plug in for Wordpress - I’ll look into that.

Thanks for the reply,

Homer.

Plugins aren’t that tricky to create. You need to create actions & filters which insert hooks (functions that run in certain parts of the page setup) allowing you to do stuff. Anybody with half a brain with PHP & MySQL (I’m talking about myself here :)) would be okay creating them.

haha, yeah… the simple reason is that I know very little php! haha, and for me, it’s easier to substitute another installation (it’s only very small anyway) for a whole lot of education.

Hey, someone’s done the work already. If you can use it, and it works… do it.

Ultimately, I’d consider what is your most important end result. Save space? Get it working asap? Learn how to do it? Develop a plugin (and learn how)?

Just my thoughts. Personally, if I wanted the results fast… I’d just install another wordpress and “simulate” the original to get the job done.

Hope that makes sense lol

Dave

Ever tried an inline PHP plugin that lets you execute code in your posts? It might work. I’m thinking, you can have PHP code and all that to handle showing the data from another database on that one page

Is the data you want to show on demand or does it stay the same for like a day until updated. You can just dump this on the server where your WP is, and let it take care showing it on your page.