SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    SitePoint Zealot Scrampy's Avatar
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

    Hope this helps,

    Dave

  3. #3
    SitePoint Evangelist rhysboy84's Avatar
    Join Date
    May 2007
    Location
    Colwyn Bay, North Wales, UK
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by homerJ_123 View Post
    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
    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.
    I'm Rhys Wynne & I blog at Winwar Media
    WP Email Capture: Free Email/Ebook Marketing Wordpress Plugin
    UK Based SEO? Tweet Your Location to #ukseohere!
    | My Brand New Brand | Twitter |

  4. #4
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Scrampy View Post
    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

    Hope this helps,

    Dave
    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.

  5. #5
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rhysboy84 View Post
    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.
    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.

  6. #6
    SitePoint Evangelist rhysboy84's Avatar
    Join Date
    May 2007
    Location
    Colwyn Bay, North Wales, UK
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by homerJ_123 View Post
    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.
    I'm Rhys Wynne & I blog at Winwar Media
    WP Email Capture: Free Email/Ebook Marketing Wordpress Plugin
    UK Based SEO? Tweet Your Location to #ukseohere!
    | My Brand New Brand | Twitter |

  7. #7
    SitePoint Zealot Scrampy's Avatar
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by homerJ_123 View Post
    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.
    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

  8. #8
    SitePoint Zealot jimmy85's Avatar
    Join Date
    Aug 2009
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •