son Posted December 4, 2012 Share Posted December 4, 2012 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 More sharing options...
justsomeguy Posted December 4, 2012 Share Posted December 4, 2012 It sounds like you don't have error reporting turned on, or else it should show an error message instead of a blank page. But as long as you're using the correct connection resource in each query it shouldn't be a problem. Link to comment Share on other sites More sharing options...
son Posted December 7, 2012 Author Share Posted December 7, 2012 I use ini_set('display_errors',1);error_reporting(E_ALL); However, I find that often when there is an issue with a db nothing shows on page (in other scenarios works fine)... Son Link to comment Share on other sites More sharing options...
justsomeguy Posted December 7, 2012 Share Posted December 7, 2012 MySQL errors aren't automatically shown, you need to check for the error condition and show the error message, e.g.: mysqli_select_db ($dbc,DB_NAME) or exit(mysqli_error($dbc)); Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now