duanchu9914 2011-10-05 15:43
浏览 32
已采纳

如何在带有doctrine 1.2的where子句中应用函数

Imagine i want to search a phone number in my DB but they are saved with different formats

Exemple : 12345678 13.36.15.36 13.654.365

What is the best way with doctrine to find a given phone.

I wish i could do something like this

Doctrine_Core::getTable('user')->create('u')->where(str_replace('.', '', u.phone) = ?, $phone)

Is there some kind of way to achieve this ?

  • 写回答

2条回答 默认 最新

  • dongzhuandian3292 2011-10-06 03:13
    关注

    I have tried using sql functions in the select method like concat and date_format. I don't see why replace wouldn't work.

    Try this:

    $q = Doctrine_Query::create()
         ->select("REPLACE(telnumber,'.','') as tel")
         ->from("user")
         ->where('tel = ?',123456);
    

    To get your results in array format:

    $q->execute(array(),Doctrine_Core::HYDRATE_ARRAY);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据