Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. include('connect.php');
  2. //include this file. This is our class
  3.  
  4. $connection = new connection_to_db;
  5. //instantiate class
  6.  
  7. $connection->make_connection("host_name", "user", "pass", "database_name");
  8. //1st param: your host name
  9. //2st param: your username
  10. //3rd param: your password
  11. //4th param: your database name
  12.  
  13. $connection->run_test_query("shouts", "id", 2);
  14. //1st param: your table name.
  15. //2nd param: which column to show.
  16. //3rd param: how many results to display.
  17.  
  18. class connection_to_db{
  19. function make_connection($host, $user, $pass, $db){
  20. global $conn;
  21. try{
  22. $conn = new pdo("mysql: host=". $host . ";dbname=". $db, $user, $pass);
  23. }catch(PDOException $error){
  24. echo $error->getMessage();
  25. die();
  26. }
  27. }
  28.  
  29. function run_test_query($shouts, $column_to_show, $count){
  30. global $conn;
  31. $query = $conn->prepare("SELECT * FROM $shouts LIMIT $count");
  32. $query->execute();
  33.  
  34. while($result = $query->fetch(PDO::FETCH_ASSOC) ){
  35. echo $result["$column_to_show"] . "</br>";
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement