Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. $servername = "localhost";
  6. $username = "root";
  7. $password = "";
  8. $dbName = "projectweek";
  9.  
  10. try {
  11. $pdo = new PDO("mysql:host=$servername;dbname=$dbName", $username, $password);
  12. // set the PDO error mode to exception
  13. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  14. echo "Connected successfully";
  15. }
  16. catch(PDOException $e)
  17. {
  18. echo "Connection failed: " . $e->getMessage();
  19. }
  20.  
  21.  
  22.  
  23. $stmt = $pdo->prepare("SELECT id, value FROM test");
  24. $stmt->execute();
  25.  
  26. while($row = $stmt->fetch()){
  27. echo $row['id'];
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement