dongyou8368 2016-06-11 17:44
浏览 59
已采纳

单列PDO上的OR运算符

I'm shifting my database connections from mysqli to PDO. While updating,I'm stuck on one query: In mysql its:

$quec='designation=10 OR designation=11 OR designation=12';
$query="select firstname,mobile,email from mt where location=".$value." and cp!=".$cpa" and (".$quec.") and dept=".$usersubdept." and mstatus=1";

Its working fine in mysqli. In PDO i wrote:

$query="select firstname,mobile,email from mt where location=:value AND cp!=:cpa AND (:quec) AND dept=:usersubdept AND mstatus=:mstatus";

Binding the values with variables using bind syntax, I'm not getting any result row. How to rectify the problem?

  • 写回答

2条回答 默认 最新

  • duangua6912 2016-06-11 17:56
    关注

    I don't think you can use :quec as a parameter, since it is actually 3 things and not a value that can be bound. Otherwise, you may have something wrong with how you're binding, perhaps, but we haven't seen your code for that. Try this:

    $query="SELECT firstname, mobile, email FROM mt WHERE location = :value AND
    cp != :cpa AND (" . $quec . ") AND dept = :dept AND mstatus = 1";
    
    $stmt = $db->prepare($query);
    $stmt->bindValue(':value',$value);
    $stmt->bindValue(':cpa',$cpa);
    $stmt->bindValue(':dept',$usersubdept);
    
    $stmt->execute();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据