Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-23 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found