Advertisement
Guest User

Untitled

a guest
May 27th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. <?php
  2. $hostname ='localhost:3306';
  3. $username = 'root';
  4. $password = '';
  5.  
  6. try
  7. {
  8. $dbh = new PDO("mysql:host=$hostname;dbname=test",$username,$password);
  9. echo 'Connected to database <br/>';
  10. $dbh->setattribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11. $ID = 1;
  12. $stmt =$dbh->prepare("select * from cities where id=:ID");
  13. $stmt->bindParam(':ID',$ID, PDO::PARAM_INT);
  14. $stmt->execute();
  15. $result =$stmt->fetchAll();
  16. foreach($result as $row)
  17. {
  18. echo $row['id'].'<br/>';
  19. echo $row['population'].'<br/>';
  20. echo $row['country_code'].'<br/>';
  21. }
  22. }
  23. catch(PDOException $e)
  24. {
  25. echo $e->getMessage();
  26. }
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement