【问题标题】:Zend - Selecting a specific fieldZend - 选择一个特定的字段
【发布时间】:2013-12-04 12:29:03
【问题描述】:

我正在尝试查询数据库以查找表中某个特定字段的结果。以下代码来自我所做的所有研究,应该只返回“id_maquina”字段,但它实际上返回了所有字段。

$hist_select=$historico->select()
    ->setIntegrityCheck(false)
    ->from(array('t1'=>'maquina_cafe'),array('t1.id_maquina'))
    ->joinLeft(array('t2'=>'maquinas'),'t1.id_maquina=t2.ID')
    ->where('t1.username = ?',$identity);

我将 *array('t1.id_maquina')* 添加到 from 方法中,以按照 stackoverflow 上的帖子中的说明将其指定为我想要的字段,但它不起作用。有人对此有什么问题有任何想法吗?

【问题讨论】:

  • 发布echo $hist_select;的结果

标签: php zend-framework select join


【解决方案1】:

您使用哪个 Zend 版本?

您从连接表中选择所有列,因为“*”(所有列)是连接的默认值。

试试:

$hist_select=$historico->select()
                      ->setIntegrityCheck(false)
                      ->from(array('t1'=>'maquina_cafe'),array('t1.id_maquina'))
                      ->joinLeft(array('t2'=>'maquinas'),'t1.id_maquina=t2.ID', array())
                      ->where('t1.username = ?',$identity);

【讨论】:

  • 为了回答您的问题,我使用的是 Zend 1.12,您的建议奏效了。我正在使用 join 但添加 joinLeft 完全是为了防止从右表返回任何字段。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2023-03-20
  • 1970-01-01
  • 2021-10-26
  • 1970-01-01
  • 2012-10-15
  • 2013-08-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多