Basics of PHP - Part 3
PHP is based around it's ability to connect to a MySQL database. Let's take a look at a script used to connect to a database
<?php
$hostname = "localhost";
$database = "db_ryanpartington.com";
$username = "ryan";
$password = "$ecr3t";
$mysqlconnection = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
?>
<?php - Tell the server to expect PHP code to follow
$hostname = "localhost"; - Define a variable called '$hostname' for later use
$database = "db_ryanpartington.com"; - Defining a variable called '$database' for later use
$username = "ryan"; - Define a variable called '$username' for later use
$password = "$ecr3t"; - Define a variable called '$password' for later use
$mysqlconnection = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); - Define a variable called '$mysqlconnection' for later use which will establish a connection to an SQL Server. If the connection fails, show error message
?> - Tell the server we've finished with PHP code
All our variables are now setup ready for the DB connection, tomorrow we'll look at making the connection.
Cheers
Ryan Partington


