bind value pdo php code example
Example 1: bind method in pdo in php
If we had a value:
$sql = "SELECT * FROM myTable WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bindValue(1,1);
$stmt->execute();
If we had two values:
$sql = "SELECT * FROM myTable WHERE id = ? and name = ?";
$stmt = $conn->prepare($sql);
$stmt->bindValue(1,1);
$stmt->bindValue(2,"alireza");
$stmt->execute();
Example 2: bind in pdo
$sql = "SELECT * FROM myTable WHERE id = :id";
$stmt = $conn->prepare($sql);
$stmt->execute([":id"=>$id]);