Advertisement
Guest User

jordy

a guest
Mar 21st, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $dbname = "toets2";
  6.  
  7. try {
  8. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  9. // set the PDO error mode to exception
  10. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11.  
  12. // prepare sql and bind parameters
  13. $stmt = $conn->prepare("INSERT INTO toets2 (voornaam, tussenvoegsel, achternaam, email)
  14. VALUES (:voornaam, :tussenvoegsel, :achternaam, :email)");
  15. $stmt->bindParam(':voornaam', $voornaam);
  16. $stmt->bindParam(':tussenvoegsel', $tussenvoegsel);
  17. $stmt->bindParam(':achternaam', $achternaam);
  18. $stmt->bindParam(':email', $email);
  19.  
  20. // insert a row
  21. $voornaam = "John";
  22. $achternaam = "Doe";
  23. $tussenvoegsel = "Test";
  24. $email = "john@example.com";
  25. $stmt->execute();
  26.  
  27. // insert another row
  28. $voornaam = "Mary";
  29. $achternaam = "Moe";
  30. $tussenvoegsel = "Test";
  31. $email = "mary@example.com";
  32. $stmt->execute();
  33.  
  34. // insert another row
  35. $voornaam = "Julie";
  36. $achternaam = "Dooley";
  37. $tussenvoegsel = "Test";
  38. $email = "julie@example.com";
  39. $stmt->execute();
  40.  
  41. echo "New records created successfully";
  42. }
  43. catch(PDOException $e)
  44. {
  45. echo "Error: " . $e->getMessage();
  46. }
  47. $conn = null;
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement