Posted By

czapata on 11/24/08


Tagged

mysql php


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vali29
bitlimakina


Quick MySQL Connection Test


 / Published in: PHP
 

  1. <?php
  2.  
  3. # Define MySQL Settings
  4. define("MYSQL_HOST", "");
  5. define("MYSQL_USER", "");
  6. define("MYSQL_PASS", "");
  7. define("MYSQL_DB", "");
  8.  
  9. $conn = mysql_connect("".MYSQL_HOST."", "".MYSQL_USER."", "".MYSQL_PASS."") or die(mysql_error());
  10. mysql_select_db("".MYSQL_DB."",$conn) or die(mysql_error());
  11.  
  12. $sql = "SELECT * FROM YourTableName";
  13. $res = mysql_query($sql);
  14.  
  15. while ($field = mysql_fetch_array($res))
  16. {
  17. echo 'FieldName1: ' . $field['fieldname1'] . '<br />';
  18. echo 'FieldName2: ' . $field['fieldname2'] . '<br /><br />';
  19. }
  20. ?>

Report this snippet  

You need to login to post a comment.