My fellow Monks, I have a delicate problem I need to solve and I need your help.

My project at work is to enable a MySQL master, slave architecture to work as one server as a read only server where the statement is routed to it only if it does nothing to the database (meaning it's only retieving data, not changing it) and the other server is a write server and I'm sure you get it, if the statement does something to the database the changes are routed through to that server and the changes made to the read only server through replication.

My question is other than subclassing DBI is there a way to do this already? The example I saw in the DBI documentation made it clear as to how to subclass DBI when creating your own connection, do, prepare and execute methods when you're only using one connection, but I'm at a loss as to how I can use two connections and have them used intelligently. I understand I need to call the SUPER::connect after I get all the needed connection information and pass back a handle and it gets messy here. I need to create two connections and have them both available. Do I bless the new class with both connections storred in a hash or do I need to do somethig else? I have an idea on how to get the new class to use the connections intelligently but that could change depending on your answer.

I'm pretty sure this has been done before and I feel like I'm reinventing the wheel here. I hope there's a simple answer to this.

Thank you for your time.
BMaximus

In reply to Subclassing DBI and creating two connections by BMaximus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.