2011-01-01 2 views
0

저는 DBAL (Doctrine DataBase Abstraction Layer)을 사용하여 쿼리를 수행하고 있습니다. 어떤 이유로 쿼리를 전달하기 전에 매개 변수를 인용 할 때 행이 반환되지 않습니다. 인용 부호를 사용하지 않으면 잘 동작합니다. 여기Doctrine DBAL 쿼리가 따옴표로 묶여서 결과를 반환하지 않는 이유는 무엇입니까?

public function get($game) 
    { 
    load::helper('doctrinehelper'); 
    $conn = doctrinehelper::getconnection(); 
    $statement = $conn->prepare('SELECT games.id as id, games.name as name, games.link_url, games.link_text, services.name as service_name, image_url 
           FROM games, services 
           WHERE games.name = ? 
           AND services.key = games.service_key'); 
    $quotedGame = $conn->quote($game); 

    load::helper('loghelper'); 
    $logger = loghelper::getLogger(); 
    $logger->debug("Quoted Game: $quotedGame"); 
    $logger->debug("Unquoted Game: $game"); 

    $statement->execute(array($quotedGame)); 
    $resultsArray = $statement->fetchAll(); 
    $logger->debug("Number of rows returned: " . count($resultsArray)); 
    return $resultsArray; 
    } 

로그가 표시 내용은 다음과 같습니다 :

여기에 내가 사용하고 코드 관련 조각입니다

01/01/11 17:00:13,269 [2112] DEBUG root - Quoted Game: 'Diablo II Lord of Destruction' 
01/01/11 17:00:13,269 [2112] DEBUG root - Unquoted Game: Diablo II Lord of Destruction 
01/01/11 17:00:13,270 [2112] DEBUG root - Number of rows returned: 0 

나는이 줄을 변경하면이에

$statement->execute(array($quotedGame)); 

을 :

$statement->execute(array($game)); 

나는이 로그에 도착 :

01/01/11 16:51:42,934 [2112] DEBUG root - Quoted Game: 'Diablo II Lord of Destruction' 
01/01/11 16:51:42,935 [2112] DEBUG root - Unquoted Game: Diablo II Lord of Destruction 
01/01/11 16:51:42,936 [2112] DEBUG root - Number of rows returned: 1 

유무 I 지방 손가락 뭔가를?

+0

인용구를 사용하면 일부 문자를 추가하기 만하면 데이터베이스에 문자열이 아닌 문자열이 추가됩니다. 그게 명백한가요? –

+0

나는 이것이 어떻게 작동하는지 이해하지 못한다고 생각한다. 필자는 Ibatis (Java DB 매퍼)와 함께 작업했으며 JDBC PreparedStatements를 사용하여 기본적으로 SQL 삽입을 방지합니다. DBAL 문서 (http://www.doctrine-project.org/docs/dbal/2.0/en/reference/data-retrieval-and-manipulation.html#update)는 기본적으로 DBAL이 이스케이프하지 않음을 나타냅니다. 따옴표 입력 매개 변수가 쿼리를 실패하게하는 문자를 추가하는 경우 어떤 상황에서 인용해야합니까? 박사 학위로 – braveterry

+0

최소한 쿼리에서 데이터를 입력하기 위해 자리 표시자를 사용하는 동안에는 전혀 인용 부호를 사용할 수 없습니다. –

답변

0

실제로 이것은 건축물 (IMO)입니다. 교리는 PHP's PDO을 기준으로합니다. PDO는 Prepared Statements와 함께 작동하므로 mysql_real_escapestring 또는 기타를 사용하여 따옴표를 쓸 필요가 없습니다. ORM은 기본 설계 목표를 매우 핵심적으로 가지고 있으며 PDO를 사용하면 상당히 안전합니다.

+0

데이터베이스를 두 번 호출하면 매우 효과적이라고 말할 수는 없습니다. –

+0

충분히 공정하고 작은 수정을했습니다.) – DrColossos

관련 문제