How to use an array in query()

Notice: This thread is very old.
netteman
Member | 125
+
0
-

Hi,

I'd like to do this

$arr = array("x" => 1, "y" => 2);
$this->db->query("SELECT * FROM text WHERE id = ? OR id = ?", $arr);

but Nette says “There are more placeholders than passed parameters”.

Is it possible to use an array of values to fill the ? in the query?

Thanks :)

CZechBoY
Member | 3608
+
+1
-

Use method queryArgs, which uses 1 parameter as 1 item in array. Method query uses 1 function parameter as 1 query parameter – so you passed 1 array parameter instead of 2.

netteman
Member | 125
+
0
-

Thank you!

For others: this code works

$arr = array(1, 2);
$this->db->queryArgs("SELECT * FROM texty WHERE id_text = ? OR id_text = ?", $arr);