drevls8138 2016-02-09 12:51
浏览 129
已采纳

将PHP变量传递给oci_parse中的sql查询

I am passing a PHP varibale into a oracle sql query. but its not taking it properly giving me ORA errors like - invalid character. I tried escaping the varibale as \'$sid\', this makes error go, but the query doesnt return anything. Is there a way to pass PHP variable to oracle query

if(isset($_POST['action']))
{
   $sid = $_POST['action'];
   $stid = oci_parse($conn, 'SELECT emp from table emp='$sid'');
   oci_execute($stid);
}

I have removed to the database connection part for brevity.

  • 写回答

1条回答 默认 最新

  • douying6206 2016-02-09 13:49
    关注

    'SELECT emp from table emp=\'$sid\'' is a string that you pass exactly as it is to Oracle, this is why it doesn't work.

    You need to use oci_bind_by_name to bind a placeholder to a PHP variable.

    Example:

    $variable = 42;
    $stid = oci_parse($conn, 'SELECT col_name FROM tbl_name WHERE col_name > :num;');
    oci_bind_by_name($stid, ":num", $variable);
    oci_execute($stid);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料