Posted By

mswallace on 03/18/08


Tagged

mysql database php query connection


Versions (?)


Advertising

Website Promotion DIRECTORY is a crucial factor for all websites that need to gain better organic search engine rankings and increase website traffic.
Submitting your website as part of your Web Promotion strategy to our SEO friendly and high traffic Business Directory for review is an excellent way to gain a valuable backlink and increase your websites visibility online.

Submit Site


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 






Expand | Embed | Plain Text
  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.

Download royalty free graphics