Jump to content

Connect to two dbs at the same time


Recommended Posts

Hi there,I have an issue to retrieve and store data from/to two different dbs. On each page at top I have

include_once ('/complete/path/domain.com/scripts/db.php'); // connect to databasemysqli_set_charset($dbc, 'utf8');

As now I need to also access another db I have created an additonal file to db.php which is called db2.php. They are different in the connect and select statements (remainder identtical) as

$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD);mysqli_select_db ($dbc,DB_NAME);for db.phpand$dbc2 = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD);mysqli_select_db ($dbc2,DB_NAME);for db2.php

As long as each is accessed separately everything works fine. However, I have now a web page where both dbs need to be accessed and I tryed:

include_once ('/complete/path/domain.com/scripts/db.php'); // connect to databasemysqli_set_charset($dbc, 'utf8');include_once ('/complete/path/domain.com/scripts/db2.php'); // connect to databasemysqli_set_charset($dbc2, 'utf8');

which does not work. From the insertion of db2.php everything blank on page. If I insert it right at the top it is an empty page, if lower down it is blank from insertion point onwards which shows me that this is the incorrect way to use db2.php. How should I properly access the second db? The data is retrieved for main part of page where first db brings in data that sits in header and footer of relevant page... Thanks,Son

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...