1
2<?php
3/* Execute a prepared statement by passing an array of values */
4$sql = 'SELECT name, colour, calories
5 FROM fruit
6 WHERE calories < :calories AND colour = :colour';
7$sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
8$sth->execute(array(':calories' => 150, ':colour' => 'red'));
9$red = $sth->fetchAll();
10$sth->execute(array(':calories' => 175, ':colour' => 'yellow'));
11$yellow = $sth->fetchAll();
12?>
13
14
1
2<?php
3/* Exécute une requête préparée en passant un tableau de valeurs */
4$sql = 'SELECT nom, couleur, calories
5 FROM fruit
6WHERE calories < :calories AND couleur = :couleur';
7$sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
8$sth->execute(array(':calories' => 150, ':couleur' => 'red'));
9$red = $sth->fetchAll();
10$sth->execute(array(':calories' => 175, ':couleur' => 'yellow'));
11$yellow = $sth->fetchAll();
12?>
13
14