Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. <?php
  2. $host = "10.0.2.2";
  3. $user = "root";
  4. $pwd = "root";
  5.  
  6. if (!$link = mysql_connect( $host, $user, $pwd )) {
  7. echo 'Could not connect to mysql';
  8. exit;
  9. }
  10.  
  11. if (!mysql_select_db('my_database', $link)) {
  12. echo 'Could not select database';
  13. exit;
  14. }
  15.  
  16. $sql = 'SELECT * FROM products';
  17. $result = mysql_query($sql, $link);
  18.  
  19. if (!$result) {
  20. echo "DB Error, could not query the database\n";
  21. echo 'MySQL Error: ' . mysql_error();
  22. exit;
  23. }
  24.  
  25. while ($row = mysql_fetch_assoc($result)) {
  26. echo $row['id']." | ".$row['name'];
  27. }
  28.  
  29. mysql_free_result($result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement