Code
<?php $host = 'host'; $user = 'username'; $pass = 'password'; $db = 'database'; $conn = mysql_connect($host, $user, $pass) or die("Could not connect to database: " . mysql_error()); $dbselect = mysql_select_db($db, $conn) or die("Could not select database '" . $db . "': " . mysql_error()); ?> Explained Basically <?php is telling the server that the it is a PHP script and that this is the start of the script and you probably guessed what ?> means, this means it is the end of the PHP script. Next $host and $user, these are connection details to the mysql server, you can find out your details by asking your web host provider. $host is normally localhost.
$conn is a function in this case its defined as connect to the mysql database or die("Could not connect to database: " . mysql_error()); This means that if the PHP file cannot connect using the details you provided it will display a message saying Could not connect to database. $dbselect = mysql_select_db The last part, this is selecting the database which you provided, the number of mysql databases will depend on your host, you may have an unlimited amount of databases so it selects a database you want it to connect to. To make this work all you need to do is change the variables which i have colored in yellow then you insert that into your html code (i.e. dreamweaver or just open note pad) and make sure you save it as a .php file otherwise this will not work when you upload it to your web server. This concludes our tutorial!