×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Lionel Crasson
Added: Sep 5, 2012 10:53 AM
Modified: Sep 5, 2012 11:03 AM
Views: 1772
Tags: no tags
  1. <?php
  2. //1.Create a database connection
  3. $connection = mysql_connect("localhost","root","");
  4. if(!connection){
  5.         die("database connection failed:".mysql_error());
  6. }
  7. //2.Select a database to use
  8. $db_select = mysql_select_db("DBnme";$connection);
  9. if(!$db_select){
  10.         die ("Database selection failed:".mysql_error());
  11. }
  12. ?>
  13.  
  14.  
  15. <?php
  16. //3.perform database query
  17. $result = mysql_query("SELECT*FROM subjects",$connection);
  18. if(!$result){
  19.         die ("Database query failed:".mysql_error());
  20. }
  21.  
  22. //4.use returned data
  23. while ($info = mysql_fetch_array($result)){
  24.         echo $info["menu_name"]." ".$info["position"]."<br />";
  25. }
  26. ?>
  27.  
  28.  
  29. <?php
  30. //5. Close connection
  31. mysql_close($connection);
  32. ?>