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

  • SEARCH
  • Home
  • 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 3235514
In Process

The Archive Base Latest Questions

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

The result I’m trying to achieve involves having an application with a database with

  • 0

The result I’m trying to achieve involves having an application with a database with minimal tables that store data regarding users on the system, this database would be used to verify user’s login details when they login to the application. What I want to be able to do is to dynamically connect to another database once the user has logged in, based on details stored about that user in the main database.

Basically I want each user on the system to have their own database, connect to that database once they login, and be able to use common db model classes (since each user’s db will have the same tables as every other user’s db).

Is this possible? And if so, how would I implement the dynamic db connection (let’s say in the action that validates their login details).

Any help would be greatly appreciated.

  • 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-17T17:30:56+00:00Added an answer on May 17, 2026 at 5:30 pm

    The simplest answer is not to make a second connection, but just change the default schema after you determine the name that the given user needs.

    For example, fetch the name of the secondary db for a given user:

    $db = Zend_Db::factory(...options...);
    $secondary_db = $db->query("SELECT secondary_db 
        FROM user_data WHERE user = ?", $userid)
       ->fetchOne();
    

    Then run a query to change the schema. Note the USE statement does not support being a prepared statement, so you have to execute it using the driver API:

    $db->getConnection()->query("use $secondary_db");
    

    Now if you reference a table without qualifying its schema, you’ll get the table instance in the secondary database. This includes any query you run via the Zend_Db adapter or Table classes, etc.

    But the USE statement only works if your secondary databases reside on the same database instance as your primary database with the user details. And also this assumes you don’t need to re-authenticate the user against the database because each user has different database-level credentials.

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

Sidebar

Related Questions

No related questions found

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.