Advertisement
Guest User

Untitled

a guest
Mar 21st, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Jostein
  5.  * Date: 20.03.2016
  6.  * Time: 22:30
  7. **/
  8.  
  9.  
  10.  
  11. $servername = "mysql.stud.ntnu.no";
  12. $username = "andrkje_jobbquiz";
  13. $password = "K5lt2qpp";
  14. $dbname = "jobbquiz";
  15.  
  16. try {
  17.     $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  18.     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  19.     $stmt = $conn->prepare("SELECT *FROM postal_code");
  20.     $stmt->execute();
  21.  
  22.     // set the resulting array to associative
  23.     $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  24.     foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
  25.         echo $v;
  26.     }
  27. }
  28. catch(PDOException $e) {
  29.     echo "Error: " . $e->getMessage();
  30. }
  31. $conn = null;
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement