나는 모든 곳을 보았습니다. 아마도 내 질문의 모든 변형을 찾아 낼 수 있었고 모든 제안을 시도했습니다 ... 연결하려고합니다. 두 개의 서로 다른 위치에있는 두 개의 서로 다른 DB ($ local과 $ remote)에 연결하고 두 번째 DB 만 작동합니다. 나는 반환 mysql_select_db를 이동하려고했습니다PHP - 두 개의 MySQL 연결, 두 번째 작업 만
//-------------Local DB Connection:
$local = mysql_connect("localhost","root","...");
if (!$local)
{
die('Could not connect: ' . mysql_error());
}
$sel1 = mysql_select_db("new", $local);
//-------------Remote DB Connection:
$remote = mysql_connect("...","...","...",true);
if (!$remote)
{
die('Could not connect: ' . mysql_error());
}
$table = "...";
//---------function selecting from local:
function fncGrabNemsis($ele,$val){
mysql_select_db("new", $local);
$result = mysql_query("SELECT * FROM new.tblvalues
WHERE fldelement='$ele' AND fldcode='$val'",$local);
$tmprow = mysql_fetch_array($result);
return (isset($tmprow['fldvariable'])?$tmprow['fldvariable']:$val);
}
//----------Select run from Remote:
mysql_select_db("ImdxTest", $remote);
$result = mysql_query("SELECT * FROM ImdxTest.$table WHERE ClientID = ... AND IncidentNum = '$fldINCID'", $remote) or die(mysql_error());
$row = mysql_fetch_array($result);
() 함수는 당신이 생각할 수있는 모든 곳에서 호출하고 단지 다른 모든 것들에 대해 ... 어떻게됩니까 : 여기에 ("..."= 숨김) 내 코드의 샘플입니다 $ local이 정의되어 있지 않거나 $ 로컬 연결을 사용하려고하는 mysql 함수가 매개 변수가 리소스가 될 것으로 예상한다는 PHP 오류가 발생합니다. 저는 두 연결이 개별적으로 작동하기 때문에 두 연결이 모두 작동한다는 사실을 알고 있습니다. 두 번째 연결 ($ remote) 만 작동합니다 ... 모든 제안에 대해 감사드립니다!
BTW : 귀하의 쿼리는 SQL injections에 열려 있습니다. [mysql_real_escape_string] (http://www.php.net/manual/de/function.mysql-real-escape-string.php)을 사용해보십시오. – CodeZombie