Convert ODBC SQL query to use prepared statements

孤者浪人 提交于 2020-04-16 02:39:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!