Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. <HTML>
  2. <head>
  3. </head>
  4. <BODY>
  5. <?php
  6. $servername = "localhost";
  7. $username = "test";
  8. $password = "none";
  9. $dbname = "myDBPDO";
  10.  
  11. try {
  12. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  13. // set the PDO error mode to exception
  14. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  15. $sql = "INSERT INTO MyGuests (firstname, lastname, email)
  16. VALUES ('John', 'Doe', 'john@example.com')";
  17. // use exec() because no results are returned
  18. $conn->exec($sql);
  19. echo "New record created successfully";
  20. }
  21. catch(PDOException $e)
  22. {
  23. echo $sql . "<br>" . $e->getMessage();
  24. }
  25.  
  26. $conn = null;
  27. ?>
  28. <p>this is stuff below the php script</p>
  29. </BODY>
  30. </HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement