How do you connect to multiple MySQL databases on a single webpage?

后端 未结 11 2348
青春惊慌失措
青春惊慌失措 2020-11-22 05:06

I have information spread out across a few databases and want to put all the information onto one webpage using PHP. I was wondering how I can connect to multiple databases

11条回答
  •  一整个雨季
    2020-11-22 05:46

    if you are using mysqli and have two db_connection file. like first one is

    define('HOST','localhost');
    define('USER','user');
    define('PASS','passs');
    define('**DB1**','database_name1');
    
    $connMitra = new mysqli(HOST, USER, PASS, **DB1**);
    

    second one is

        define('HOST','localhost');
        define('USER','user');
        define('PASS','passs');
        define(**'DB2**','database_name1');
    
        $connMitra = new mysqli(HOST, USER, PASS, **DB2**);
    

    SO just change the name of parameter pass in mysqli like DB1 and DB2. if you pass same parameter in mysqli suppose DB1 in both file then second database will no connect any more. So remember when you use two or more connection pass different parameter name in mysqli function

提交回复
热议问题