Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. <?php
  2.  
  3. function connect(){
  4.  
  5. $servername = "localhost";
  6. $username = "root";
  7. $password = "";
  8. $dbName = "blog";
  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. connect();
  24.  
  25. $stmt = $pdo->prepare("SELECT ID, Title, Text FROM blog_posts");
  26. $stmt->execute();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement