I’m doing the following query in a snippet:
$query = $modx->newQuery('Tariff');
$query->where("(`tariff`.`property` = :prop) AND ((`tariff`.`date_from` between :from AND :to ) OR ( `tariff`.`date_to` between :from AND :to ))");
$query->prepare(array(
'prop' => array('value' => 1, 'type' => PDO::PARAM_INT),
'from' => array('value' => '2011-01-01', 'type' => PDO::PARAM_STR),
'to' => array('value' => '2011-12-31', 'type' => PDO::PARAM_STR)
));
The result in MODx error log is:
PHP warning: PDOStatement::execute() [<a href='pdostatement.execute'>pdostatement.execute</a>]: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound
[2011-01-19 01:07:08] (ERROR @ /index.php) Error HY093 executing statement:
Array
(
[0] => HY093
)
Any ideas why I get the invalid parameter number error?
MODx Revolution / MAMP / OS X
-
MODX Staff
- 10,725 Posts
You cannot reuse a placeholder multiple times in a prepared statement. They must all be uniquely named placeholders, e.g. :from1 and :from2, :to1 and :to2 ...
Right. I did that at first and got the same error...
I have now concatenated the where clause and passed by the prepare which works...
Don’t understand why it throws the error when I use the prepare.
MODx Revolution / MAMP / OS X