Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » External Database

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1877 Views
  • Fuzz10
    Avatar
    Community Member
    786 Posts

    External Database Link to this post

    Continuing this old thread :
    http://silverstripe.org/archive/show/120

    The thread is about connecting to external MySQL MySQL databases. And the guys figures out that in order for this to work, the core MySQLDatabase class needs to be altered to create a new MYSQL Link every time ....

    Sam ends with :
    "Setting the new_link parameter seems appropriate; the alternative would be to call "USE xxx" before each database query which would get annoying, especially given that multi-database access is a pretty rare scenario."

    My questions:
    Is this still the "official" way of pulling data from an external database ? Should I expect any adverse results from creating a new DB_link every time (garbage collection / mem usage / performance issues etc.)

    Thanks !

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: External Database Link to this post

    Wow, thats a seriously old thread ;) You can have named connections via DB::getConn(<my-name>) now

  • Gene
    Avatar
    Community Member
    41 Posts

    Re: External Database Link to this post

    This is the code for DB::getConn()...

    /**
    * Get the global database connection.
    * @return Database
    */
    static function getConn() {
       return DB::$globalConn;
    }

    It doesn't look like it supports named connections unless I'm missing something. Can you post an example?

    Thanks.

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: External Database Link to this post

    It's in 2.4 alpha1, sorry!

  • Gene
    Avatar
    Community Member
    41 Posts

    Re: External Database Link to this post

    Thanks for the quick response.

    Just one more thing to look forward to in 2.4

    1877 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.