开发者

zend based where clause disappearing

开发者 https://www.devze.com 2023-02-01 00:05 出处:网络
I have a weird problem using socialEn开发者_运维技巧gine DB class (based on zend framework). I wrote something like this:

I have a weird problem using socialEn开发者_运维技巧gine DB class (based on zend framework). I wrote something like this:

$statusTable = Engine_Api::_()->getDbtable('actions', 'activity');
$myPosts = $statusTable->fetchAll($statusTable->select()
    ->where('subject_id = ?',$id)
    ->where('comment_count > ?',0)
    ->where('type = ?',$type)
    ->where('date > ?',$newer_than)
    ->order('date DESC')
    ->limit(intval($num_items)));

Its a part of a plugin a made, the problem is the query generated is somthing like this:

SELECT `engine4_activity_actions`.*
FROM `engine4_activity_actions`
WHERE (subject_id = 5) AND (comment_count > 0) AND (type = ) AND (date > )
ORDER BY `date` DESC LIMIT 10

You can see that the $type and the $newer_than have disappeared, even though they have values ($type='status', $newer_than='01/01/2000')

EDIT: It seems to respond only to integers and not strings, if i replace the 'status' with 0 it shows up in the query.

The server runs on php 5.3.2


There's a third optionnal argument on the where() method which is the type of your argument. Depending on your DB adapter it can maybe get an important thing to tell for the Zend_Db_Select query builder. So you could try

->where('subject_id=?',$subject,'TEXT')

ZF API indicates as well "Note that it is more correct to use named bindings in your queries for values other than strings", this can help the query builder, to get the real type of your args, so you could try as well this way:

$myPosts = $statusTable->fetchAll($statusTable->select()
->where('subject_id=:psubject')
(...)
,array('psubject'=>$subject));
0

精彩评论

暂无评论...
验证码 换一张
取 消