\n";
$db = new PDO('mysql:host=localhost;dbname=Test');
$stmt = $db->prepare("SELECT * FROM T1");
$stmt->execute();
while($row = $stmt->fetch()) {
$f1 = $row['F1'];
$f2 = $row['F2'];
echo "$f1 $f2
\n";
}
$stmt->closeCursor();
// short form
echo "short form:
\n";
$db = new PDO('mysql:host=localhost;dbname=Test');
$stmt = $db->prepare("SELECT * FROM T1 WHERE F1 > :F1");
$stmt->execute(array(':F1' => 2));
while($row = $stmt->fetch()) {
$f1 = $row['F1'];
$f2 = $row['F2'];
echo "$f1 $f2
\n";
}
$stmt->closeCursor();
// bindValue
echo "bind value:
\n";
$i = 2;
$db = new PDO('mysql:host=localhost;dbname=Test');
$stmt = $db->prepare("SELECT * FROM T1 WHERE F1 > :F1");
$stmt->bindValue(':F1', $i);
$i = 4;
$stmt->execute(); // find all >2
while($row = $stmt->fetch()) {
$f1 = $row['F1'];
$f2 = $row['F2'];
echo "$f1 $f2
\n";
}
$stmt->closeCursor();
// bindParam
echo "bind param:
\n";
$i = 2;
$db = new PDO('mysql:host=localhost;dbname=Test');
$stmt = $db->prepare("SELECT * FROM T1 WHERE F1 > :F1");
$stmt->bindParam(':F1', $i);
$i = 4;
$stmt->execute(); // find all >4
while($row = $stmt->fetch()) {
$f1 = $row['F1'];
$f2 = $row['F2'];
echo "$f1 $f2
\n";
}
$stmt->closeCursor();
// bind column
echo "bind column:
\n";
$db = new PDO('mysql:host=localhost;dbname=Test');
$stmt = $db->prepare("SELECT * FROM T1");
$stmt->execute();
$stmt->bindColumn('F1', $f1);
$stmt->bindColumn('F2', $f2);
while($row = $stmt->fetch()) {
echo "$f1 $f2
\n";
}
$stmt->closeCursor();
?>