Advertisement
dbcalmada

DB Fetch Assoc

May 6th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. <?php
  2. $link = mysqli_connect("localhost", "dbadmin", "p9zzW@", "contacts");
  3.  
  4. $query = "SELECT id, firstname, lastname, email FROM contacts ORDER BY lastname";
  5.  
  6. $result = mysqli_query($link, $query);
  7.  
  8. if ($result) {
  9.  
  10.     /* fetch associative array */
  11.     while ($row = mysqli_fetch_assoc($result)) {
  12.         printf ("%s %s %s %s\n", $row["id"], $row["firstname"],    
  13.         $row["lastname"], $row["email"]);
  14.     }
  15.  
  16.     /* free result set */
  17.     mysqli_free_result($result);
  18. }
  19.  
  20. /* close connection */
  21. mysqli_close($link);
  22. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement