Clear previous params query

21 views
Skip to first unread message

Khắc Đạo Phan

unread,
Oct 24, 2015, 12:06:26 AM10/24/15
to NotORM
Here is my query:

$song = $this->db->select('*')
                  ->where('is_played', 0)
                  ->where('song_id', $id)
                  ->order('id')
                  ->limit(1);

echo $this->db->select('*')->where('id', 2);

Result is: SELECT * FROM play WHERE (is_played = 0) AND (song_id = '1075371488') AND (id = 2) ORDER BY id LIMIT 1

How to clear preivous params query?

Allysson David

unread,
Oct 24, 2015, 12:15:51 AM10/24/15
to not...@googlegroups.com
I can't see the table name anywhere, thus I can guess that the element $this->db actually stores the object representing the table "play".
All of NotORM methods both change the object which have called any of its methods and return itself to allow chaining, meaning that the one responsible for storing the "where-params" is the table-related object which was already modified previously.

How to solve? Instead of storing something like $notorm->play() in $this->db, please store the constructed $notorm object itself and run the queries like this:

$song = $this->db->play()->select('*')
                  ->where('is_played', 0)
                  ->where('song_id', $id)
                  ->order('id')
                  ->limit(1);

echo $this->db->play()->select('*')->where('id', 2);

Also, "*" is the default value when selecting columns, you don't need to explicitly call that ->select('*').

Khắc Đạo Phan

unread,
Oct 24, 2015, 12:44:12 AM10/24/15
to NotORM
Thank you for your quickly response.

I got your idea, it help me so much. :)

Vào 11:15:51 UTC+7 Thứ Bảy, ngày 24 tháng 10 năm 2015, Allysson David đã viết:
Reply all
Reply to author
Forward
0 new messages