dongle7553 2017-02-06 11:53
浏览 17
已采纳

Zend Db在哪里

I have the following table on MSSQL server:

Superheroes: id,name,real_name,power

And as Input I have the following array:

$heroes=["Superman","Batman","Wonder Woman"]

And I want to fetch their real names using Zend Framework 2.3.2. Therefore on My model I have this function:

public function getHeroesRealNames(array $superHeroesNames)
{
  /**
  * @var Zend\Db\Adapter\AdapterInterface
  */
  $db=$this->db;
  $sql=new Sql($db);
  $qb=new Select('dbo.Superheroes');

  $qb->columns(['real_name'])->where('name IN (?)',$superHeroesNames);

  $query_string=$sql->getSqlStringForSqlObject($bq)
  var_dump($query_string);//Debug Output
}

But the var_dump for debugging purposes returns:

SELECT [dbo.Superheroes].[real_name] AS [real_name] FROM [dbo.Superheroes] WHERE name IN ('')"

Instead of the full query. How can I fix that? please keep in note that I DO NOT use var_dump in production.

  • 写回答

1条回答 默认 最新

  • doushaju4901 2017-02-06 12:18
    关注

    I think you need to use the In Predicate as where method requires this but the method will also create the correct predicate for you if given the correct array or strings.

    You can find the docs here .. https://framework.zend.com/apidoc/2.1/classes/Zend.Db.Sql.Predicate.In.html

    You don't have to use the class directly, you can do ...

    Basic example:

    $select->from('Superheroes')->where(array(
        'name' =>$superHeroesNames,
    ));
    

    You can find examples of this on the docs page too https://framework.zend.com/manual/2.2/en/modules/zend.db.sql.html#where-having

    Please note the second argument of where method is the combination type, i.e AND or OR

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作