*/
echo "\n\n";
$DB_NAME = *****;
$connect = @mysql_pconnect("*****", "*****", "*****"); // Connects to the database server
$select = @mysql_select_db($DB_NAME); // Selects and opens the correct database
// If the connection to the database fails, print connection error
if ((!$connect) || (!$select))
{
echo '';
}
else // If the database connects successfully continue
{
if (isset($_GET['projectName']) ) // Checks to see if the GET variable is set.
{
// Sanitizes input and intializes the GET variable
$tableName = mysql_real_escape_string($_GET['projectName']);
$resultGetReport= mysql_query("SELECT * FROM `$tableName`");
if (!$resultGetReport) // if the project does not exist print an XML failure
{
echo '';
}
else // Prints the entire table as XML
{
echo '';
echo '' . $tableName . '';
echo '';
if (mysql_num_rows($resultGetReport) > 0) // Checks to see if the project table has at least 1 record
{
$numFields = mysql_num_fields($resultGetReport); // Gets the number of fields found in the table
$fields = array();
for($i=0; $i < $numFields; $i++) // Iterates through the headers, storing them all in an array
{
$fieldName = mysql_fetch_field($resultGetReport);
$fieldName = ucwords($fieldName->name); // Capitalizes the first letter of every word
array_push($fields, $fieldName); // Adding in newest header to the array
}
while($row = mysql_fetch_row($resultGetReport)) // Goes through each row of the table adding in the headers from the fields array
{
echo '';
$x = 0; // Sets header number
foreach($row as $cell)
{
echo '<' . $fields[$x] . '>' . $cell . '' . $fields[$x] . '>';
$x++; // Since the number of rows and headers have to be equal, this merely adds one and sets up the next header
}
echo '';
}
}
else
{
echo "Table is Empty";
}
echo '';
echo '';
}
}
else // If the incorrect number of GET parameters are passed in, then it fails and prints an XML failure
{
echo '';
}
// @mysql_close(); // Closes all open DB connections
}
?>