Maybe this is totally wrong to do, but...
I need to do a query like this:
SELECT * FROM DATABASE1, DATABASE2 WHERE DATABASE1.users.name = DATABASE2.users.name
If I do it with phpmyadmin it works, but on php the page blocks.
The way I connect to mysql i'm using,
$result = new mysqli(server, user, pass, database)
I can see why it doesn't work, I'm connecting to only one database, but how does phpmyadmin do it then? How can I do it?
I've seen other posts but I want to CROSS the info on the 2 databases, and I havent found anything like that.
[EDIT] An actual example of my code would be:
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 just:
function db_connect()
{
$result = new mysqli('localhost', $user, $pass, 'quehaceshoy_testing');
$result->set_charset("utf8");
if (!$result)
return false;
return $result;
}
This query makes the page to "load" indefinetly.
Thanks.
I test-wrote a script below and it seems to be working fine without failing....
<?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]);
}
?>
May be you'll need to post your code here. Is it that your data set is large? Please post your code so that we may check and guide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With