Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. <?php
  2. $hostname='localhost';
  3. $username='';
  4. $password='';
  5.  
  6. try {
  7. $dbh = new PDO("mysql:host=$hostname;dbname=id6953396_infinity",$username,$password);
  8.  
  9. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
  10. echo 'Connected to Database<br/>';
  11.  
  12.  
  13. $sql = "INSERT INTO students (student_name, student_email, student_city)
  14. VALUES ('Bob', 'bob@bob.bob', 'Bobdon')";
  15.  
  16.  
  17. if ($dbh->query($sql)) {
  18. echo "New record created successfully";
  19. }
  20. else{
  21. echo "Data not sucessfully inserted";
  22. }
  23.  
  24. $dbh = null;
  25. }
  26. catch(PDOException $e)
  27. {
  28. echo $e->getMessage();
  29. }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement