*/ 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 failure XML if ((!$connect) || (!$select)) { echo ''; } else // If the database connects successfully continue { if ( (isset($_GET['projectName'])) && (isset($_GET['variableName'])) ) // Checks to see if all GET variables are set { // Sanitizes input and intializes the GET variables $tableName = mysql_real_escape_string($_GET['projectName']); $metricName = mysql_real_escape_string($_GET['variableName']); date_default_timezone_set("America/New_York"); // Changes date function to EST. $dateModified = strval(date('Y-m-d H:i:s')); // Converts date to string for DB datetime field. $queryCheckTable = "SHOW tables like \"$tableName\""; $resultCheckTable = mysql_query($queryCheckTable); if (mysql_num_rows($resultCheckTable) <= 0) // if the project does not exist print an XML failure { echo ''; } else // Creates and sets the variable if it does not exist, or overwrites it with the new value if it already exists { $queryCheckField = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = '$DB_NAME' AND table_name = '$tableName' AND column_name = '$metricName'"; $resultCheckField = mysql_query($queryCheckField); if (mysql_num_rows($resultCheckField) <= 0) // If variable does not exists, it creates it and sets it. { mysql_query("ALTER TABLE `$tableName` ADD COLUMN $metricName int(11) NOT NULL DEFAULT 0"); echo ''; } else { echo ''; } // If the variable already exists it does nothing. } } 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 } ?>