php - Connetions with another database and server on subquery -
how can connect db1
, server1
sub query
? thanks!
$link1 = mysql_connect("server1","user1","pas1"); mysql_select_db('db1', $link1); $link2 = mysql_connect("server2","user2","pas2") or die(mysql_error()); mysql_select_db("db2", $link2) or die(mysql_error()); $sql="select db2.`e`.`entity_id` , db2.a.value klantnr, db2.b.value voornaam,db2.c.value achternaam, db2.`t`.`value` telfnr, db2.ce.email db2.`tablename` e left outer join db2.customer_entity_varchar on db2.a.entity_id = db2.e.parent_id , db2.a.attribute_id = '133' db2.ce.email not in(select db1.email_addresses.email_address db1.tablename) , db2.a.value in (select db1.accounts_cstm.custid_c db1.accounts_cstm ) group db2.ce.email"; $result = mysql_query($sql,????) or die(mysql_error());
i have solution (way) error(operand should contain 1 column(s))
$link1 =mysql_connect("server1","user1","pas1"); mysql_select_db('db1', $link1); $link2 = mysql_connect("server2","user2","pas2") or die(mysql_error()); mysql_select_db("db2", $link2) or die(mysql_error()); $query="select email_addresses.email_address db1.tablename"; $result = mysql_query($query,$link1) or die(mysql_error()); $select=array(); $row=mysql_fetch_array($result); $select[]=$row["email_address"]; $select = "('" . implode ("','", $select) . "')"; mysql_query("set sql_big_selects=1",$moonen_link); $sql="select `e`.`entity_id` , a.value klantnr, b.value voornaam, c.value achternaam, `t`.`value` telfnr, ce.email `tablename` e left outer join customer_entity_varchar on a.entity_id = e.parent_id , a.attribute_id = '133' ce.email not in($select) group ce.email"; $result = mysql_query($sql,$link2) or die(mysql_error());
i think "user1" should have access (privilege) both database if on same mysql server.
then connect 1 database with
$link1 = mysql_connect("server1","user1","pas1"); mysql_select_db('db1', $link1);
and request on both server $link1:
$sql="select db2.`e`.`entity_id` , db2.a.value klantnr, db2.b.value voornaam,db2.c.value achternaam, db2.`t`.`value` telfnr, db2.ce.email db2.`tablename` e left outer join db2.customer_entity_varchar on db2.a.entity_id = db2.e.parent_id , db2.a.attribute_id = '133' db2.ce.email not in(select db1.email_addresses.email_address db1.tablename) , db2.a.value in (select db1.accounts_cstm.custid_c db1.accounts_cstm ) group db2.ce.email"; $result = mysql_query($sql,$link1) or die(mysql_error());
should ok
Comments
Post a Comment