Query various databases

Perhaps this is completely wrong, but ...

I need to make a request like this:

SELECT * FROM DATABASE1, DATABASE2 WHERE DATABASE1.users.name = DATABASE2.users.name

If I do this with phpmyadmin, it works, but on php page blocks.

The way to connect to mysql that I use is

$ result = new mysqli (server, user, password, database)

I see why this does not work, I connect to only one database, but how does phpmyadmin do it? How can i do this?

I saw other posts, but I want to redraw information about 2 databases, and I did not find anything like it.

[EDIT] Actual example of my code:

if($type == "past"){// Hago una query u otro dependiendo de si quiero pasados o futuros $query = "SELECT DISTINCT E.* FROM quehaceshoy_testing.Events E, quehaceshoy_testing.Tickets TK, quehaceshoy_testing.TypeTickets TT, quehaceshoy_testing.Tickets_Reservados2 TR, AirTicket.TICKET T WHERE ((T.Email='$this->email' AND T.idCompra = TR.idCompra AND TR.idTypeTicket_TypeTickets = TT.idTypeTicket AND E.IDEvent = TT.idEvent_Events)OR (E.email = '$this->email')) AND E.dateFinish < '".$fecha."' ORDER BY E.dateFinish DESC"; } else{ $query = "SELECT DISTINCT E.* FROM quehaceshoy_testing.Events E, quehaceshoy_testing.Tickets TK, quehaceshoy_testing.TypeTickets TT, quehaceshoy_testing.Tickets_Reservados2 TR, AirTicket.TICKET T WHERE ((T.Email='$this->email' AND T.idCompra = TR.idCompra AND TR.idTypeTicket_TypeTickets = TT.idTypeTicket AND E.IDEvent = TT.idEvent_Events)OR (E.email = '$this->email')) AND E.dateFinish >= '".$fecha."' ORDER BY E.dateFinish DESC"; } //echo $query; //$result = $this->makeQuery($query, 'RESULT'); if($conn = db_connect()){ $result = $conn->query($query); if(!$result){ //echo '<p>Unable to get list from database.</p>'; //echo $conn->error; return false; } } 

and db_connect is simple:

 function db_connect() { $result = new mysqli('localhost', $user, $pass, 'quehaceshoy_testing'); $result->set_charset("utf8"); if (!$result) return false; return $result; } 

This request makes the page "loadable" undefined.

Thanks.

+7
source share
1 answer

I tested-wrote a script below and it seems to work fine without crashing ....

  <?php $con = mysql_connect("localhost","root",""); mysql_select_db("test"); $con1 = mysql_connect("localhost","root",""); mysql_select_db("test1"); $query = "SELECT * FROM test1.`manager` INNER JOIN test.employee ON test1.`manager`.id= test.employee.mgr"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf("ID: %s Name: %s", $row[0], $row[1]); } ?> 

You may need to post your code here. Is your dataset really big? Please post your code so we can check and guide.

+2
source

All Articles