Advertisement
Guest User

Untitled

a guest
May 14th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. <?php
  2.  
  3. function dbConnect(){
  4.  
  5. $hostname = 'localhost';
  6. $username = 'tbcj857';
  7. $mysql_pass = 'm2d59';
  8. $database = 'tbcj857';
  9.  
  10. $conx = mysql_connect ($hostname, $username, $mysql_pass)
  11.    or die ("Can't connect to MySQL" .mysql_error() );
  12.  
  13. mysql_select_db($database)
  14.    or die ("Can't select that database" .mysql_error() );
  15.  
  16. return $conx;
  17. }
  18.  
  19. dbConnect();
  20. $sql = "SELECT * FROM users WHERE id = 3";
  21. $result = mysql_query($sql) or die(mysql_error() );
  22.  
  23. //Now your data is in $result, which is a data type of resource:
  24. //mySQL_fetch_assoc() fetches data *a row at a time* from a resource as an
  25. //associative array.
  26.  
  27. //We therefore have to loop over the result to get all the rows out,
  28. //or we would only get the first row. We'll use a 'while' loop to do this:
  29.  
  30. //while (condition is ture) {do this code}
  31. //ie, "as long as there's another row of $result, put it in $row"
  32.  
  33. $row = mysql_fetch_row($result);
  34.  
  35. //echo '<b>' . $row['fname'] . "'s data: </b><br/>\n";
  36.  
  37. foreach ($row as $key => $value){
  38.  
  39. //echo "\t";
  40.  
  41. echo "$key : $value <br/>";
  42.  
  43. }
  44.      
  45.  
  46.       //echo "<br/>\n";
  47.  
  48. //}
  49.  
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement