Hi people...
While creating a small API, I came across something peculiar. I have an action that retrieves a database record by id and user, using the code below:
$rule = PriceRules::query()
->where("id = :id:")
->andWhere("reseller_id = :user:")
->bind(["id" => $id, "user" => $this->user_data[id]])
->limit(1)
->execute();
However, this produces an empty result, although the following works just fine:
$rule = PriceRules::findFirst(
array(
'conditions' => 'id = :id: AND reseller_id = :user:',
'bind' => array('id' => $id, 'user' => $this->user_data[id])
)
);
The first piece of code produces this MySQL query:
SELECT `price_rules`.`id`, `price_rules`.`reseller_id`, `price_rules`.`deal`, `price_rules`.`price`, `price_rules`.`type`, `price_rules`.`product_id`, `price_rules`.`user_id`, `price_rules`.`active` FROM `price_rules` WHERE (`price_rules`.`id` = :id) AND (`price_rules`.`reseller_id` = :user) LIMIT :APL0 img, 1, 1
Which does not seem right to me. I see an img
tag there and I am not sure where it came from, but I suspect it's what's causing the issue...
Can anyone elaborate on this? I have used similar pieces of code before in my API, but this has never happened before...