PDO Bind Params depending on whether they exists in the query
问题 Lets say I have a mysql query which gets built depending on certain conditions: example $query = "SELECT * from `usertable` where users_active=:users_active"; if($mode=="archived") { $query .= " AND archived=:archived"; } $stmt = $dbpdo->prepare($query); $stmt->bindParam(':users_active', $users_active); $stmt->bindParam(':archived', $archived); $stmt->execute(); Now, if I run the above it will only work if $mode=="archived", as otherwise the named placeholder ":archived" will not be part of