<?
// Step 1, connect to the database server
if (!$rDatabaseConnection = mysql_connect(localhost, cantrack, bwYxXzYn))
{
// Step 1 failed, fatal error
echo 'Could not connect to database server';
}
else
{
// Step 2
// Select a database to work with
if (!mysql_select_db('simplysold_com', $rDatabaseConnection))
{
// Step 2 failed
// Not being able to select a database means we can't run queries on it.
echo 'Could not select database';
}
else
{
// Step 3
// Run a query.
// Note that the query is run on the $rDatabaseConnection that I opened in step 1.
$sQuery = "SELECT computersniagaraDate, computersniagaraID, computersniagaraCost, computersniagaraText FROM computersniagara";
if (!$rResult = mysql_query($sQuery, $rDatabaseConnection))
{
// Step 3 failed.
// The query was not executed.
// This is most likely because there is a syntax-error in the query,
// so I print the error message that MySQL gave me,
// and I print the Query that I was trying to run.
echo 'SQL query failed:';
echo mysql_error($rDatabaseConnection)."<BR>";
echo $sQuery."<BR>n";
}
else
{
// Step 4
// The query worked, now see if it gave any results
if (mysql_num_rows($rResult)>0)
{
// Step 5
// Yay, results found, process them
while ($aRow = mysql_fetch_array($rResult, MYSQL_ASSOC))
{
echo $aRow['computersniagaraID'].' '.$aRow['computersniagaraDate'].' '.$aRow['computersniagaraCost'].' '.$aRow['computersniagaraText'];
};
}
else
{
// Step 4 failed
// No results found
echo 'Your query did not return any results';
}; // end of step 4
}; // end of step 3
}; // end of step 2
}; // end of step 1
?>