Advertisement
Guest User

Untitled

a guest
Jun 18th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. <?php
  2. const HOST = 'localhost';
  3. const USER = 'abhinav';
  4. const PASS = '1234';
  5. const DB = 'abh';
  6.  
  7.  
  8. try
  9. {
  10. $conn = new PDO("mysql:host = ".HOST.";dbname = ".DB."", USER, PASS);
  11. if($conn)
  12. {
  13. echo "success";
  14. }
  15. else
  16. {
  17. echo "error";
  18. }
  19. $query = "select uid from users";
  20. foreach($conn->query($query) as $row)
  21. {
  22. echo $row['uid'];
  23. }
  24. $conn = null;
  25. }
  26. catch(PDOException $e)
  27. {
  28. echo $e->getMessage();
  29. }
  30. ?>
  31.  
  32.  
  33. //it is giving me following message ....successPHP Warning: Invalid argument supplied for foreach() in /home/abhinav/pdo_test.php on line 20....please help me how to fix it
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement