问题
I'm using ODBC (Win32) to connect to our Pervasive SQL database. I have post variables that I need to insert into SQL queries and later extract individual rows.
Here's an example of what I have so far but isn't working for some reason:
$sql_bin2=odbc_prepare($conn,'SELECT TOP 1 icitemo.value FROM icitemo WHERE icitemo.itemno = ? AND icitemo.optfield = ?');
$result_bin2=odbc_execute($sql_bin2, array($barcode, $var_bin2));
while (odbc_fetch_row($result_bin2))
{
$bin2=odbc_result($result_bin2,"VALUE");
}
Nothing gets returned. What am I doing wrong here?
回答1:
Here's the answer to this:
$sql_bin2 = odbc_prepare($conn, 'SELECT TOP 1 icitemo.value FROM icitemo WHERE icitemo.itemno = ? AND icitemo.optfield = ?');
odbc_execute($sql_bin2, array($barcode, $var_bin2));
if ($sql_bin2) {
$bin2 = odbc_result($sql_bin2,"VALUE"); }
来源:https://stackoverflow.com/questions/9603865/convert-odbc-sql-query-to-use-prepared-statements