Quick MySQL Connection Test


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.