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.
In this code the size of loading page is not increasing because we are including files based on condition.
And in this code the size of loading page is increasing because we are loading all files at start
If it is only concerned with database connection than I think you have to use
1stapproach.