php - Connect to two databases on the same host at the same time -


How can I connect to two databases at the same time if both databases are on the same host and I have both privilege Are the databases So I have DB-1 and DB-2 and in this case I want to work with the following database with two databases. I am currently using the requirement ("db.fp"); To connect to a database, but I would like to connect to both the databases.

  is required ("DB-1.php"); $ Tbl_name = "System_Info"; Mysql_connect ("$ host", "$ username", "$ password") or die ("can not connect"); Mysql_select_db ("$ db_name") or die ("can not choose db"); $ sql = "SELECT COUNT (a.student_id) from DB-1. TableA is an INNER DB-2.TableB b at a.student_id = b.student_id where a.account_status = 'Avtive' and aemesteer = '6' and b. assesor_status = 'pending' '; $ q = mysql_query ($ sql) or die ("query failed:". mysql_error ()); while ($ line = mysql_fetch_array ($ q)) {echo' '. $ line [0 ];}   

and to connect to DB-1 on DB-1, it is used for DB-1.pp

  $ host = "localhost" // hostname $ username = "root"; // mysql username $ password = ""; // mysql password $ db_name = "db-1"; // database name    

With MySQLi, you can store different DB connections in different variables.

  & lt ;? php $ mysqlOne = new mysqli ("localhost", "user", "password", "Database_1"); echo $ mysqlOne-> host_info "\ n"; $ mysqlTwo = new mysqli ("127.0.0.1", "user", "password", "database_2", 3306); $ result = $ mysqlTwo - & gt; Query ("SELECT Name FROM City LIMIT 10");   

Remember, you can also use a database connection and just change the database you are using in SQL, such as SELECT * FROM database3.city

see:

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -