パラメータ化されたステートメント
次のコード例は、パラメータをバインドしてパラメータ化されたステートメントを作成する方法を示します。
リユーザブル ステートメント
odbc_prepare 関数は、プリペアドステートメントを作成します。これは、odbc_execute への複数の呼び出しで再利用できます。ステートメントオブジェクトはパラメータ化されていないクエリのように結果をフェッチするために使用できます。
$stmt = odbc_prepare($cnx, "SELECT RespondentId, ChoiceId FROM MySurvey_Responses WHERE ChoiceText = ?");
odbc_execute($stmt, array("blue 1"));
while ($row = odbc_fetch_array($stmt)) {
echo "RespondentId = ", $row["RespondentId"], "\n";
echo "ChoiceId = ", $row["ChoiceId"], "\n";
}
odbc_execute($stmt, array("blue 2"));
while ($row = odbc_fetch_array($stmt)) {
echo "RespondentId = ", $row["RespondentId"], "\n";
echo "ChoiceId = ", $row["ChoiceId"], "\n";
}