I tried to alter OOP script presented here:
to handle two databases at once (depending on function needs), but it seems not to work at all. I get an error message: mysqli_query() expects at least 2 parameters, 1 given in ...DAL.php on line 60
private function dbconnect($usedb)
{
switch($usedb)
{
case '':
echo "Error choosing database to operate on.";
break;
case '1':
$conn = new mysqli(DB1_HOST, DB1_USER, DB1_PASSWORD,DB1_DB) or die ("<br>Could not connect to MySQL server");
//mysqli_select_db(DB1_DB,$conn) or die ("<br>Could not select the main database.");
return $conn;
break;
case '2':
$conn = new mysqli(DB2_HOST, DB2_USER, DB2_PASSWORD,DB2_DB) or die ("<br>Could not connect to MySQL server");
//mysqli_select_db(DB2_DB,$conn) or die ("<br>Could not select the client database.");
return $conn;
break;
}
}
private function query($usedb,$sql)
{
$this->dbconnect($usedb);
$res = mysqli_query($sql);
Can this work eventually? How to handle two databases at once if called from a single function that is making querying much easier? What I do wrong?