tags: apache   archive   business   charity   climbing   comic   communication   database   email   exchange   family   fm2008   hack   hardware   humour   linux   liverpool   microsoft   money   mysql   network   oes   opensource   outlook   php   pictures   process   project   quote   real_life   review   rss   science   security   software   thought   tsm   updates   webdev   website   windows  

Basics of PHP - Part 3

Tue, 28 Aug 2007 10:17:12

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