Advertisement
Guest User

Delete Dynamic

a guest
Dec 15th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public function sqlDelete($id)
  2. {
  3. $sql = "DELETE FROM " . $this->getTableName();
  4. $where1 = " WHERE";
  5. $countWhereRows = 1;
  6. $where2 = "";
  7. //Check welke Rows moeten worden verwijdered
  8. foreach ($id as $key => $value) {
  9. if ($countWhereRows == 0) {
  10. $where2 .= " " . $value;
  11. $countWhereRows++;
  12. } else {
  13. $where2 .= " " . $key . " = :" . $key;
  14. $countWhereRows -= 1;
  15. }
  16. }
  17. //Hier worden de WhereValues toegevoegd aan de Sql Query
  18. $sql = $sql . " " . $where1 . " " . $where2;
  19. if (!empty($limit)) {
  20. $sql .= " LIMIT " . $limit;
  21. }
  22. $stmt = $this->conn->prepare($sql);
  23. $bindCount = 0;
  24. //Binde de Gegevens aan de SQL Query
  25. foreach ($id as $key => $value) {
  26. if ($bindCount == 0) {
  27. $stmt->bindValue(':' . $key, $value);
  28. $bindCount++;
  29. } else {
  30. $bindCount -= 1;
  31. }
  32. }
  33. $this->resetSetAndGet();
  34. return $stmt->execute();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement