Hello everyone I am trying to get data from multiple databases by one select which i would like to sort and apply conditions on
I have database connects saved in my primary database like this
$GLOBALS['connects'] = array();
$GLOBALS['prefixes'] = array();
$sql = mysql_query("SELECT * FROM shops ORDER BY ordering ASC",$connect);
while($data = mysql_fetch_assoc($sql)){
$password = simple_decrypt($data['password']);
$GLOBALS['connects'][$data['database']] = mysql_connect($data['host'],$data['user'],$password) or die ('bad data');
$GLOBALS['prefixes'][$data['database']] = $data['prefix'];
mysql_select_db($data['database'], $GLOBALS['connects'][$data['database']]) or die ('bad select');
}
Then i make query from global array variable
$query = 'SELECT * FROM ';
$limit = count($GLOBALS['connects']);
$i = 0;
foreach($GLOBALS['connects'] as $key => $val){
if(($i+1)==$limit){
$query .= $key.'.'.$GLOBALS['prefixes'][$key].'orders';
} else {
$query .= $key.'.'.$GLOBALS['prefixes'][$key].'orders, ';
}
$i++;
}
The result is
"SELECT * FROM shop1.pr_orders, shop2.pl_orders, shop3.ps_orders, shop4.pt_orders"
now i would like to make it work also add WHERE condition and ORDER BY
right now it should show every order but instead it returns false
HINT:
lets pretend chosen tables from databases have NOTHING in common