bind in pdo

Solutions on MaxInterview for bind in pdo by the best coders in the world

showing results for - "bind in pdo"
Emilia
23 Sep 2019
1If we had a value:
2
3$sql = "SELECT * FROM myTable WHERE id = ?";
4$stmt = $conn->prepare($sql);
5$stmt->bindValue(1,1);
6$stmt->execute();
7
8If we had two values: 
9
10$sql = "SELECT * FROM myTable WHERE id = ? and name = ?";
11$stmt = $conn->prepare($sql);
12$stmt->bindValue(1,1);
13$stmt->bindValue(2,"alireza");
14$stmt->execute();
Isaure
23 Jan 2021
1$sql = "SELECT * FROM myTable WHERE id = ?";
2$stmt = $conn->prepare($sql);
3$stmt->execute([$id]);
Émeric
14 Apr 2019
1$sql = "SELECT * FROM myTable WHERE id = :id";
2$stmt = $conn->prepare($sql);
3$stmt->execute([":id"=>$id]);