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 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理