Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6110435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:30:55+00:00 2026-05-23T14:30:55+00:00

I am trying to write values to 2 databases (need not be simultaneously) when

  • 0

I am trying to write values to 2 databases (need not be simultaneously) when the saveAll function is called. This does not apply to all tables but only 4 out of the 10 tables in the 2 databases.

My current logic, in Pseudocode:

    $updateOk = $model->saveAll(...);

    if (!$updateOk)
      return error;

    /* start second source synchronizing */
    $model->changeDataSource('second');
    $updateOk = $model->saveAll(...);

    $model->changeDataSource('default');
    if (!$updateOk)
        return error;

    return;

The issue with this is that sometimes it does not write to the second source, resulting in inconsistencies.

I need some advice on how to best solve this issue. I have 3 possible ideas:

  1. Follow the code above and add checks to make sure things get saved and if it doest, rollback the default to maintain consistency
  2. Write a server script that does a replication every time a saveAll() is called. (Resource intensive and not really scalable)
  3. Use a combo of both. Do a check for consistency before saving and do a script replication once a day

Which is the best way or are there better ways of implementing this requirement? Any ways to ensure consistencies?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:30:55+00:00Added an answer on May 23, 2026 at 2:30 pm

    The solution possibly lies in database table replication (set up your second database as a slave, configured to replicate only specific tables).

    Also, how will you ever scale this?

    This way, you only need to worry about writing to the DB once (your models are going to get very bloated if you need all this extra code to write to two every time), plus you are allowing your app to scale horizontally in the future (think if your app was so big you required 20 x database servers?).

    Another solution would be to create a shell task, scheduled on a cron job to move the data, but I would consider replication first.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not a database guy (as this question will show). I'm trying to write
I'm trying to write a function : Input: Source range, Source value, output range,
Im trying to write a function for adding category: function addCategory() { $cname =
I have a CKEditor custom plugin I'm trying to write, but need some help
BACKGROUND I'm trying to write a function query query('type', 'parameters', 'bind_types') which I can
I am trying to update a Microsoft report. What it does is write out
I am trying to merge 2 databases with the same schema together, and this
I've been working on trying to write a function that will grab the POST
I am trying to write a simple regex to match a percentage value range
I'm trying to generate code that takes a StringBuilder, and writes the values of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.