Tutorial: Doing basic MySQL database stuff

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:

$host = 'localhost';
$username = 'yourusername';
$password = 'yourpassword';
$databasename = 'yourdbname';

//don't edit this stuff okay?

$connect = mysql_connect($host, $username, $password);
$selectdb = mysql_select_db($databasename);

if($connect == true){
	echo 'Connected fine!';
} else {
	echo 'Bad Username or Password.....or host dummy!!!!';
}

if($selectdb == true){
	echo 'Connected to DB master :D ';
} else {
	echo 'Cant find that database....did we connect?';
}

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

Posted by VoiDeT

Categorised under PHP
Bookmark the permalink or leave a trackback.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

or