I don't understand the difference between two following code block. The first block is longer than the second and I have to determine the type of $id => PDO::PARAM_INT, $name => PDO::PARAM_STR
. The second is concise. Please help me understand the difference between them. Thank you so much.
$stmt = $db->prepare("SELECT * FROM table WHERE id=:id AND name=:name");
$stmt->bindValue(':id', $id, PDO::PARAM_INT);
$stmt->bindValue(':name', $name, PDO::PARAM_STR);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt = $db->prepare("SELECT * FROM table WHERE id=:id AND name=:name");
$stmt->execute(array(':name' => $name, ':id' => $id));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
Please let me know what should I use? I know that two above code blocks have the same result. But which way should i use?