Alex
Искусственный Интеллект
(117099)
3 года назад
/* Выполнение запроса с передачей ему массива параметров */
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < ? AND colour = ?');
$sth->execute(array(150, 'red'));
$red = $sth->fetchAll();
$sth->execute(array(175, 'yellow'));
$yellow = $sth->fetchAll();
$dish = $db->quote($_POST['dish_search']);
$dish = strtr($dish, array('_' => '\_', '%' => '\%'));
$stmt = $db->query("SELECT dish_name, price FROM dishes WHERE dish_name LIKE $dish");
или так:
$dish = strtr($dish, array('_' => '\_', '%' => '\%'));
$stmt = $db->prepare('UPDATE dishes SET price = 1 WHERE dish_name LIKE ?');
$stmt->execute(array($_POST['dish_name']));
и почему так правильнее.