いくつかのクエリを実行するためにDoctrine DataBase Abstraction Layer(DBAL)を使用しています。何らかの理由で、パラメータをクエリに渡す前にパラメータを引用すると、何も返されません。私はそれを引用符で渡すとき、それはうまく動作します。ここで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脂肪指何か?
引用符を付けると、文字列を追加するだけで、データベースに文字列以外の文字列が追加されます。それは明らかではありませんか? –
私はこれがどのように動作するのか分かりません。私はIbatis(Java DBマッパー)を使って作業しました。デフォルトでは、JDBC PreparedStatementsを使用してSQLインジェクションから保護しています。 DBALのドキュメント(http://www.doctrine-project.org/docs/dbal/2.0/ja/reference/data-retrieval-and-manipulation.html#update)は、DBALがデフォルトでエスケープしないことを示しているようです。入力パラメータを引用すると、クエリが失敗する文字が追加された場合、どのような状況で引用する必要がありますか?ドクターとして – braveterry
少なくとも、プレースホルダを使用してデータをクエリに入れている間は、引用のための使用は全くありません。 –