Model query() does not seem to work properly

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...



31.3k

Hi,

can't repoduce :


   object(PDOStatement)#65 (1) {
      ["queryString"]=>
      string(237) "SELECT `eleve`.`ID`, `eleve`.`nom`, `eleve`.`prenom`, `eleve`.`classe`, `eleve`.`groupe`, `eleve`.`manip`, `eleve`.`debut`, `eleve`.`fin`, `eleve`.`actif` FROM `eleve` WHERE (`eleve`.`ID` = :id) AND (`eleve`.`classe` = :user) LIMIT :APL0"
    }
    ["_sqlStatement":protected]=>
    string(237) "SELECT `eleve`.`ID`, `eleve`.`nom`, `eleve`.`prenom`, `eleve`.`classe`, `eleve`.`groupe`, `eleve`.`manip`, `eleve`.`debut`, `eleve`.`fin`, `eleve`.`actif` FROM `eleve` WHERE (`eleve`.`ID` = :id) AND (`eleve`.`classe` = :user) LIMIT :APL0"
    ["_bindParams":protected]=>
    array(3) {
      ["id"]=>
      string(1) "1"
      ["user"]=>
      string(5) "2A"
      ["APL0"]=>
      int(1)
    }
    ["_bindTypes":protected]=>
    array(1) {
      ["APL0"]=>
      int(1)
    }
    ["_rowCount":protected]=>
    int(1)
  }

and I get a valid Simple resultset object.

Indead it looks weird, but im using query in few places and don't have this issue.