2014-03-27 4 views
0

XMLRPC의 내 기능이 다음과 같이 작동하는지 확인하십시오. 최신 내용 인 경우 내 웹 사이트에 내용이 이미 있는지 확인하고 필요한 경우 업데이트하십시오. 나는 그것을 확인하기 위해 숫자 (두 가지 콘텐츠 유형 모두 같은 수를 가질 수 있음)를 확인합니다. 해시 (고유)와 유형입니다.Select with select where where where 절

콘텐츠가 하나 뿐이고 기능이 정상적으로 작동하기 전에 번호와 해시 대신 콘텐츠 유형을 확인해야합니다. 그게 문제입니다. 제가 해보려한다면, 저는 빈 anwser를 얻었습니다. 내 기능은 다음과 같습니다.

$query = db_query("SELECT (table_num.field_num) FROM (table_num, table_type) WHERE table_num.entity = table_type.entity AND table_num.field_num = :num AND table_type.field_type = :type", array(':num' => $num, ':type' =>$type)); 
foreach ($query as $record) { 
if($record->rowCount()==0) return 0; 
else { 
$query = db_query("SELECT (table_hash.field_hash) FROM (table_hash, table_type) WHERE table_hash.entity = table_type.entity AND table_hash.field_hash = :hash AND table_type.field_type = :type", array(':hash' => $hash, ':type' =>$type)); 
foreach ($query as $record) { 
if($record->rowCount()==1) return 1; 
else{ 
$query = db_query("SELECT (table_num.entity_id) FROM (table_num, table_type) WHERE table_num.entity = table_type.entity AND table_num.field_num = :num AND table_type.field_type = :type", array(':num' => $num, ':type' =>$type)); 
foreach ($query as $record) { 
echo $record->field_entity_id; 
} 
return $record; 

P.S. 0을 반환하면 내 DB에 존재하지 않으며, 1은 업데이트해야 할 때 최신이고 엔터티 일 때입니다.

죄송합니다. 긴 SQL 용으로 사용하기 시작했지만 사용하기 시작했습니다. 누군가 내가 빈 anwser를 얻는 이유를 알고 있습니까?

답변

1

검색어를 작성하는 방식이 위험하기 때문에 변수를 이스케이프 처리하지 않아도 SQL 삽입이 가능합니다.

$query = db_query("SELECT (table_num.field_num) FROM table_num WHERE table_num.field_num = $num AND table_type.field_type = $type"); 

당신은 사용할 수 있습니다 : 대신

$query = db_query("SELECT (table_num.field_num) FROM table_num WHERE table_num.field_num = :num AND table_type.field_type = :type", array(':num' => $num, ':type' =>$type)); 

드루팔은 당신이 어떤 취약점으로 이어질하지 않습니다 알 수 있도록 그들을 삽입하기 전에 변수를 소독한다이 방법.

내가 실제로 완전히 귀하의 질문에 요구하고있다 이해하지 않는다 - 당신이 그것을 명확히 할 수 있다면 내 SQL 변경됩니다 @Felix 내가 너무 도움을 줄 수 있다면 내가 볼 조금 ...

+0

감사합니다, 곧 내 질문을 업데이 트됩니다. 나는 그것이 지금 당장 이해하기 어렵다는 것을 압니다. – RTD