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 Worker_Reference_WID, Legal_Name_Last_Name FROM [CData].[Human_Resources].Workers WHERE Legal_Name_Last_Name = ?"); odbc_execute($stmt, array("Morgan 1")); while ($row = odbc_fetch_array($stmt)) { echo "Worker_Reference_WID = ", $row["Worker_Reference_WID"], "\n"; echo "Legal_Name_Last_Name = ", $row["Legal_Name_Last_Name"], "\n"; } odbc_execute($stmt, array("Morgan 2")); while ($row = odbc_fetch_array($stmt)) { echo "Worker_Reference_WID = ", $row["Worker_Reference_WID"], "\n"; echo "Legal_Name_Last_Name = ", $row["Legal_Name_Last_Name"], "\n"; }