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 8599413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:23:34+00:00 2026-06-12T01:23:34+00:00

i am programming in php talking to mysql database. the code requires the use

  • 0

i am programming in php talking to mysql database. the code requires the use of different include files(connection to different databases) based on the user logged in.
i was just wondering, what would be the correct way to do that. should include all the files in the beginning and then specify the database name inside my queries or keep including the files and not change the query.
for example, for user a the database access required is uae

if($user == 'a'){
include('/home/xxxxxxx/xxxxxx/connection.php'); // connection to database x
$qry = "SELECT * FROM sometable";
} elseif($user == 'b'){
include('/home/xxxxxxx/xxxxxx/connect.php'); // connection to database y
$qry = "SELECT * FROM sometable";
}

would the above be better or the following:-

include('/home/xxxxxxx/xxxxxx/connection.php'); // connection to database x
include('/home/xxxxxxx/xxxxxx/connect.php'); // connection to database y
if($user == 'a'){
$qry = "SELECT * FROM databaseX.sometable";
} elseif($user == 'b'){
$qry = "SELECT * FROM databaseY.sometable";
}

please advise. help is 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-06-12T01:23:35+00:00Added an answer on June 12, 2026 at 1:23 am

    In this code the size of loading page is not increasing because we are including files based on condition.

    if($user == 'a'){
    include('/home/xxxxxxx/xxxxxx/connection.php'); // connection to database x
    $qry = "SELECT * FROM sometable";
    } elseif($user == 'b'){
    include('/home/xxxxxxx/xxxxxx/connect.php'); // connection to database y
    $qry = "SELECT * FROM sometable";
    }
    

    And in this code the size of loading page is increasing because we are loading all files at start

    include('/home/xxxxxxx/xxxxxx/connection.php'); // connection to database x
    include('/home/xxxxxxx/xxxxxx/connect.php'); // connection to database y
    if($user == 'a'){
    $qry = "SELECT * FROM databaseX.sometable";
    } elseif($user == 'b'){
    $qry = "SELECT * FROM databaseY.sometable";
    }
    

    If it is only concerned with database connection than I think you have to use 1st approach.

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

Sidebar

Related Questions

I am programming in PHP mysql. I have recently got into OOP programming. So
I've been using this to gender a random 12 character string: // lost-in-code.com/programming/php-code/php-random-string-with-numbers-and-letters $ch
I'm new to PHP and MySQL (and programming in general) and I'm trying to
It has been a year I am programming using PHP. I use Procedural programming
For programming PHP with TextMate (OS X) I'd like it to use Allman indentation:
Programming PHP in Eclipse PDT is predominately a joy: code completion, templates, method jumping,
After ages of programming in php this question seems really weird still to me.
I'm a newbie in php programming and i can't make it finding where is
Quick background: I'm programming in PHP, I have a domain model with a separate
hello I'm new to PHP programming and I migrated from ASP .net to PHP..

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.