douxuelv7755 2019-01-03 14:38
浏览 82
已采纳

如何在moodle中为现有查询添加类似条件

I have a query with multiple conditions check. I want to add the condition to check the with like clause. I tried like this.

$params1['email'] =$DB->sql_like('email', '%'.$voucher_query.'%');

and I am passing the params1 value to query condition. I am getting the query as different and it is not working. This is the query I am getting.

SELECT COUNT('x') FROM tbl_order WHERE active_ind = ? AND id = ? AND email = ? [array ( 0 => 1, 1 => 236909, 2 => 'email LIKE %emelchor% COLLATE utf8_bin ESCAPE \'\\\\\'', )]

the email condition is checking with equals to but not with like exactly. Can anyone help me out.?

Thanks in advance

  • 写回答

1条回答 默认 最新

  • dongtuo0828 2019-01-03 15:44
    关注

    You haven't shown the function call you are doing to retrieve the records, but I'm guessing it looks something like:

    $DB->get_records('order', $params);
    

    This simple DB syntax is only suitable for equals comparisons, if you want to do something more complex, you will need to rewrite it to use the get_records_select function instead, e.g.

    $select = 'active_ind = :ind AND id = :id AND '.$DB->sql_like('email', ':email');
    $email = '%'.$DB->sql_like_escape($voucher_query).'%';
    $params = ['ind' => $ind, 'id' => $id, 'email' => $email];
    $result = $DB->get_records_select('order', $select, $params);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。