Tutorial: Doing basic MySQL database stuff

This tutorial is quite easy. If you want to connect to a mysql database you can use something like this:

  1. $host = 'localhost';
  2. $username = 'yourusername';
  3. $password = 'yourpassword';
  4. $databasename = 'yourdbname';
  5.  
  6. //don't edit this stuff okay?
  7.  
  8. $connect = mysql_connect($host, $username, $password);
  9. $selectdb = mysql_select_db($databasename);
  10.  
  11. if($connect == true){
  12.   echo 'Connected fine!';
  13. } else {
  14.   echo 'Bad Username or Password.....or host dummy!!!!';
  15. }
  16.  
  17. if($selectdb == true){
  18.   echo 'Connected to DB master :D';
  19. } else {
  20.   echo 'Cant find that database....did we connect?';
  21. }

So this code basically connects to the database and says hi!
More to come on DB Functions ;)

Post a Comment