Zend 框架查询与连接

发布于 2024-10-02 00:49:35 字数 918 浏览 9 评论 0原文

我正在尝试使用 zend 框架复制此查询:

SELECT 
    activitytype.description, 
    activity.datecompleted

FROM
    clientactivity
INNER JOIN activity
    ON activity.activityID = clientactivity.activityid
INNER JOIN activitytype
    ON activitytype.activitytypeid = activity.activitytypeid

WHERE
    clientactivity.clientid = 100

这就是我到目前为止所拥有的:

$select = $dbTable->select(Zend_Db_Table::SELECT_WITH_FROM_PART);

$select->setIntegrityCheck(false);
$select->where('clientactivity.clientid = ?', $clientID);

$select->join('activity', 'activity.activityid = clientactivity.activityid');
$select->join('activitytype', 'activitytype.activitytypeid = activity.activitytypeid');

$select->columns(array('activitytype.description', 'activity.datecompleted'));

我似乎在列选项方面遇到问题,它似乎并没有限制列,我最终得到 查询中列列表中的 clientactivity.* 等。

我做错了什么?

谢谢, 马丁

I am trying to replicate this query using zend framework:

SELECT 
    activitytype.description, 
    activity.datecompleted

FROM
    clientactivity
INNER JOIN activity
    ON activity.activityID = clientactivity.activityid
INNER JOIN activitytype
    ON activitytype.activitytypeid = activity.activitytypeid

WHERE
    clientactivity.clientid = 100

This is what I have so far:

$select = $dbTable->select(Zend_Db_Table::SELECT_WITH_FROM_PART);

$select->setIntegrityCheck(false);
$select->where('clientactivity.clientid = ?', $clientID);

$select->join('activity', 'activity.activityid = clientactivity.activityid');
$select->join('activitytype', 'activitytype.activitytypeid = activity.activitytypeid');

$select->columns(array('activitytype.description', 'activity.datecompleted'));

I seem to be having problems with the columns option, it doens't seem to be limiting the columns and I am ending up with
clientactivity.* etc in the column list in the query.

What am I doing wrong?

Thanks,
Martin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

靑春怀旧 2024-10-09 00:49:35

尝试代替 $select->columns();

$select->from('activitytype.description', 'activity.datecompleted');

参考 - http://framework.zend.com/manual/en/zend .db.select.html

更新:

这个示例使我们成为一个通用数据库处理程序:

$db = Zend_Db::factory('Pdo_Mysql', array(
            'host'     => '127.0.0.1',
            'username' => 'yourusername',
            'password' => 'somepassword',
            'dbname'   => 'yourdbname'
        ));

 $select = $db->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
 $select->from('tableName','fieldName')
         ->join('joinTable', 'joinTable.keyId = tableName.keyId',array())
         ->where('tableName.userId = ?', $userId);

 $resultSet = $db->fetchAll($select);

关键部分是连接语句末尾的空白数组,它指定不返回任何记录从连接表中。

Try instead of the $select->columns();

$select->from('activitytype.description', 'activity.datecompleted');

Reference - http://framework.zend.com/manual/en/zend.db.select.html

UPDATE:

This example makes us of a generic database handler:

$db = Zend_Db::factory('Pdo_Mysql', array(
            'host'     => '127.0.0.1',
            'username' => 'yourusername',
            'password' => 'somepassword',
            'dbname'   => 'yourdbname'
        ));

 $select = $db->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
 $select->from('tableName','fieldName')
         ->join('joinTable', 'joinTable.keyId = tableName.keyId',array())
         ->where('tableName.userId = ?', $userId);

 $resultSet = $db->fetchAll($select);

The key piece is the blank array at the end of the join statements that specifies no records to be returned from the joined table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文