Posted By

mswallace on 03/18/08


Tagged

mysql database php query connection


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

Wiederkehr
bsisco
Nix
vali29
love


PHP connecting and query MySQL DB


 / Published in: PHP
 

  1. <?php
  2. //create db connection
  3. $connection = mysql_connect("localhost", "user", "password");
  4. if(!$connection)
  5. {
  6. die("Database connection failed:" . mysql_error());
  7. }
  8.  
  9. // select a dtabase to use
  10. $db_select = mysql_select_db("database name", $connection);
  11. if(!$db_select)
  12. {
  13. die("Database selection failed:" . mysql_error());
  14. }
  15.  
  16.  
  17. ?>
  18.  
  19. <body>
  20. $result = mysql_query("SELECT * FROM tablename", $connection);
  21.  
  22. while ($row = mysql_fetch_array($result))
  23. {
  24. echo $row["rownamehere"]." ".$row["rownamehere"]."<br/>";
  25. }
  26. ?>
  27. </body>
  28.  
  29. <?php
  30. mysql_close($connection);
  31. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: PixelMin on October 22, 2008

"

You need to login to post a comment.