Comments - Access to more databases

 
3 years, 11 months ago Lon Hammonds

This sounds like a connection definition problem. You should be using two different connections, one per database. When building your queries, you should be referencing the database connection for the database you want to query.

Example:

$cnn_db1 = mysqli_connect($Servername, $Username, $Password, $Database1);
$cnn_db2 = mysqli_connect($Servername, $Username, $Password, $Database2);
$rst_query1 = mysqli_query($cnn_db1, "SELECT * FROM Users")
$rst_query2 = mysqli_query($cnn_db2, "SELECT * FROM Users")
mysqli_free_result($rst_query1);
mysqli_free_result($rst_query2);
mysqli_close($cnn_db2);
mysqli_close($cnn_db1);
 
5 years, 9 months ago Ian Gilfillan

If you don't specify a database in the identifier name, the default, or current, database, will be used. See USE. To avoid ambiguity, you can use the dbname.tablename syntax. See Identifier Qualifiers and SELECT.

 
5 years, 9 months ago Alberto Bonardi

Thank you Ian. I'll see USE option because I would like to avoid having to enter all the prefixes with the database name !

 
5 years, 9 months ago Alberto Bonardi

Hello, I tried to set "USE myDbName" when opening the database, but unfortunately something is wrong because I keep seeing the data from the other database. Unfortunately I'm afraid I'll have to modify all the queries by adding the prefix with the database name! Thanks anyway

 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.