Answer the question
In order to leave comments, you need to log in
How to use a named and unnamed variable at the same time in PDO?
If I substitute variables in the query string, then everything naturally works, but from a security point of view, this is not correct:
//Так всё работает
$brand = implode(',',$brand);
$sql = "SELECT * FROM models WHERE category_id=$cat_id AND brand_id IN ($brand)";
$stmt = $pdo->prepare($sql);
$stmt->execute();
//Так ошибки
$in = str_repeat('?,', count($brand) - 1) . '?';
$sql = "SELECT * FROM models WHERE category_id= :cat_id AND brand_id IN ($in)";
$stmt = $pdo->prepare($sql);
$stmt->execute(array('cat_id'=>$cat_id, $brand));
$in = str_repeat('?,', count($brand) - 1) . '?';
$sql = "SELECT * FROM models WHERE category_id=$cat_id AND brand_id IN ($in)";
$stmt = $pdo->prepare($sql);
$stmt->execute($brand);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question