Parameterized Statements
The following code example shows how to bind parameters to create parameterized statements.
Reusable Statements
The odbc_prepare function creates prepared statements, which can be re-used across multiple calls to odbc_execute. The statement object can be used to fetch results like a non-parameterized query.
$stmt = odbc_prepare($cnx, "SELECT SalesPerson, Name FROM Contact WHERE Country = ?");
odbc_execute($stmt, array("U.S.A. 1"));
while ($row = odbc_fetch_array($stmt)) {
echo "SalesPerson = ", $row["SalesPerson"], "\n";
echo "Name = ", $row["Name"], "\n";
}
odbc_execute($stmt, array("U.S.A. 2"));
while ($row = odbc_fetch_array($stmt)) {
echo "SalesPerson = ", $row["SalesPerson"], "\n";
echo "Name = ", $row["Name"], "\n";
}