Question: i want to select two databases in php but when i code it gives error how i select two databases here is my code which i already tried:

```
 <?php
@session_start ();
$dbhost = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "domain102,main102";
$mysqli = new mysqli ($dbhost, $dbusername, $dbpassword, $dbname);
if ($mysqli->connect_errno)
{
    echo ("Failed to connect to MySQL: " . $mysqli->connect_error);
}

$GLOBALS ['mysqli'] = $mysqli;
 ?>

```

here is error

```
 Warning: mysqli::mysqli(): (HY000/1049): Unknown database 'domain102,main102'

```

Answer: 
Use mysqli::select\_db to switch databases on the same server:

```
$link = new mysqli($dbhost, $dbusername, $dbpassword, $dbname);
then

$link->select_db($dbname2);

```
If you want to use two databases then
Just use following code:

```
$dbhost = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "domain102";
$mysqli = new mysqli ($dbhost, $dbusername, $dbpassword, $dbname);

$dbname = "main102";
$mysqli1 = new mysqli ($dbhost, $dbusername, $dbpassword, $dbname);

```