ODBC prepared statements in PHP

前端 未结 6 547
后悔当初
后悔当初 2020-12-05 19:33

I\'m trying to use odbc_prepare and odbc_execute in PHP as follows:

$pstmt=odbc_prepare($odb_con,\"select * from configured where param_name=\'?\'\");
$res=o         


        
6条回答
  •  没有蜡笔的小新
    2020-12-05 19:45

    You should not enclose variables in quotes in a prepared statement:

    
    $pstmt=odbc_prepare($odb_con,"select * from configured where param_name=?");
    $res=odbc_execute($pstmt,array(" 'version'"));
    
    

    should be:

    
    $pstmt=odbc_prepare($odb_con,"select * from configured where param_name=?");
    $res=odbc_execute($pstmt,array("version"));
    
    

    Question marks represent parameter placeholders, the value passed is meant to represent an unescaped, unenclosed value, which will be properly escaped by the SQL interpreter.

提交回复
热议问题