function display_duck_blinds() { $dbinfo = initialize_db_info(); #report_database_settings($dbinfo); try { $db_link = db_connect($dbinfo); db_select($db_link, $dbinfo); } catch (Exception $e) { echo report_exception("Database Connection", $e); echo report_database_settings($dbinfo); } $sql = generate_blind_list_sql(); $result_rows = mysql_query($sql, $db_link); if (!$result_rows) { echo $sql; $message = 'Invalid query: ' . mysql_error() . "\n"; echo $message; throw new Exception('No Results.'); } echo '<table>'; while ($row = mysql_fetch_array($result_rows, MYSQL_ASSOC)) { //echo generate_blind_row($row); } echo '</table>'; }
function registerX($email, $password, $first_name, $last_name) { // Register new person with db // Return true or error message // Connect to db $dbinfo = initialize_db_info(); //report_database_settings($dbinfo); try { $db_link = db_connect($dbinfo); db_select($db_link, $dbinfo); } catch (Exception $e) { echo report_exception("Database Connection", $e); echo report_database_settings($dbinfo); } // Check if username is unique $uniqueSql = "select * from login where email='" . $email . "'"; echo report_name_value("uniqueSql", $uniqueSql); $result_rows = mysql_query($uniqueSql, $db_link); if (!$result_rows) { throw new Exception('Could not execute query'); } $numberOfRows = mysql_num_rows($result_rows); if ($numberOfRows > 0) { throw new Exception('That email is taken - go back and choose another one.'); } $insert_sql = generateUserInsertSql($email, $password, $first_name, $last_name); $result_rows = mysql_query($insert_sql, $db_link); if (!$result_rows) { throw new Exception('Could not register you in database - please try again later. (' . $insert_sql . ')'); } return true; }
function saveNewHuntCountReport($huntReportId, $huntCount) { // Connect to the database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $insertHuntCountReportSql = generateHuntCountReportInsertSql($huntReportId, $huntCount); // Insert the hunt details information in the database. $result = mysql_query($insertHuntCountReportSql, $dbLink); if (!$result) { echo $insertHuntCountReportSql; throw new Exception('Failed to insert hunt count report'); } }
function getSpeciesNameById($speciesId) { // Connect to database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $getSpeciesSql = "SELECT common_name FROM species WHERE id=" . $speciesId; $result = mysql_query($getSpeciesSql, $dbLink); if (!$result) { throw new Exception('no results: ' . $getSpeciesSql); } $row = mysql_fetch_assoc($result); $speciesName = $row['common_name']; return $speciesName; }
function insertNote($noteContent) { // Make connection to the database. $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $insertNoteSql = generateInsertNoteSql($noteContent); $result = mysql_query($insertNoteSql, $dbLink); if (!$result) { echo $insertNoteSql; throw new Exception('Insert Note Failed: ' . $insertNoteSql); } $noteId = getInsertId(); return $noteId; }
function getHarvetsListByHuntDetailsId($huntDetailsId) { // Connect to the database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $harvestCountList = array(); $sql = generateHarvestListByHuntDetailsId($huntDetailsId); $result = mysql_query($sql, $dbLink); $row = mysql_fetch_assoc($result); while ($row) { $oneHarvestCount = createHarvestCountFromRow($row); $harvestCountList[$oneHarvestCount->getSpeciesId()] = $oneHarvestCount; $row = mysql_fetch_assoc($result); } return $harvestCountList; }
function getHuntDatesList($season) { // Connect to database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $huntDatesList = array(); $findHuntDatesByYearSql = generateFindHuntDatesByYearSql($season); $result = mysql_query($findHuntDatesByYearSql, $dbLink); $row = mysql_fetch_assoc($result); while ($row) { $oneHuntDate = $row['hunt_date']; $huntDatesList[] = $oneHuntDate; $row = mysql_fetch_assoc($result); } return $huntDatesList; }
function getHarvestCounts($huntId) { // Connect to the database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $reportHarvestList = array(); $reportHarvestSql = generateReportHarvestSql($huntId); //var_dump($reportHarvestSql); $result = mysql_query($reportHarvestSql, $dbLink); $row = mysql_fetch_assoc($result); while ($row) { $oneReportHarvest = createReportHarvestFromRow($row); $reportHarvestList[] = $oneReportHarvest; $row = mysql_fetch_assoc($result); } return $reportHarvestList; }
function getAnonymousHarvestCountsForASeason($season) { // Connect to the database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $reportCountList = array(); $reportSql = generateAnonymousHarvestCountsForASeasonSql($season); var_dump($reportSql); $result = mysql_query($reportSql, $dbLink); $row = mysql_fetch_assoc($result); while ($row) { $oneSpeciesCount = createSpeciesCountFromRow($row); $reportCountList[] = $oneSpeciesCount; $row = mysql_fetch_assoc($result); } return $reportCountList; }
function getHarvestCountBySpeciesForSeason($speciesId, $season) { // Connect to database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $getHarvestCountBySpeciesForSeasonSql = generateHarvestCountBySpeciesForSeasonSql($speciesId, $season); $result = mysql_query($getHarvestCountBySpeciesForSeasonSql, $dbLink); if (!$result) { throw new Exception('no results'); } $row = mysql_fetch_assoc($result); $count = $row['count']; if (!isset($count)) { $count = 0; } return $count; }
function getDisplay($label) { $displayList = array(); // Connect to database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $sql = generateDisplayListSql($label); $result = mysql_query($sql, $dbLink); if ($result) { if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $currentDisplay = createDisplayFromRow($row); $displayList[] = $currentDisplay; } } } return $displayList; }
function getAllCommonNames() { // connect to db $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $getCommonNameSql = "SELECT * FROM common_names ORDER BY common_name"; $result = mysql_query($getCommonNameSql, $dbLink); if (!$result) { echo $getCommonNameSql; throw new Exception('no results'); } $row = mysql_fetch_assoc($result); while ($row) { $oneCommonName = createCommonNameFromRow($row); $commonNameList[] = $oneCommonName; $row = mysql_fetch_assoc($result); } return $commonNameList; }
function getAllEvents($numberOfEvents) { // Connect to Database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $getAllEventsSql = "SELECT * FROM event_log ORDER BY create_date DESC LIMIT " . $numberOfEvents; $result = mysql_query($getAllEventsSql, $dbLink); if (!$result) { echo $getAllEventsSql; throw new Exception('no results'); } $row = mysql_fetch_assoc($result); while ($row) { $oneEvent = createEventFromRow($row); $eventList[] = $oneEvent; $row = mysql_fetch_assoc($result); } return $eventList; }
function getSeasonId($season) { $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $huntIdSql = generateHuntIdSql($hunt); $result = mysql_query($huntIdSql, $dbLink); if (!$result) { echo $huntIdSql; throw new Exception('Failed to retrieve hunt id'); } $row = mysql_fetch_assoc($result); $currentHuntId = $row['id']; return $currentHuntId; }
function saveNewHunter($newHunter) { // Connect to database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $insertNewHunterSql = "INSERT INTO hunter SET first_name='" . $newHunter->getFirstName() . "', "; $insertNewHunterSql .= "last_name='" . $newHunter->getLastName() . "' "; $result = mysql_query($insertNewHunterSql, $dbLink); if (!$result) { echo $insertNewHunterSql; throw new Exception('Failed to insert hunter'); } }
function removeUserHunterId($userId) { $updateRemoveUserHunterIdSql = generateRemoveUserHunterIdUpdateSql($userId); // Connect to the database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); //var_dump($updateRemoveUserHunterIdSql); // Update the users information in the database. $result = mysql_query($updateRemoveUserHunterIdSql, $dbLink); if (!$result) { echo $updateRemoveUserHunterIdSql; throw new Exception('Failed to update user'); } }
<?php session_start(); require_once dirname(__FILE__) . '/bagCheckIncludes.php'; $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $insertSql = "INSERT INTO bc_day (bc_date, bc_area) VALUES('2013-07-16', 'Area Jeff')"; $result = mysql_query($insertSql, $dbLink); if (!$result) { echo $insertSql; throw new Exception('Insert Test Failed'); } $insertId = mysql_insert_id(); echo $insertId;
function savePassword($email, $newPassword) { $updatePasswordSql = generateChangePasswordSql($email, $newPassword); // Connect to the database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); // Update the users password in the database. $result = mysql_query($updatePasswordSql, $dbLink); if (!$result) { echo $updatePasswordSql; throw new Exception('Password could not be changed.'); } }
function updateStringValue($year, $blindNumber, $priority, $columnName, $newValue) { // Connect to database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $updateStringValueSql = generateUpdateStringValue("blinds", $year, $blindNumber, $priority, $columnName, $newValue); //var_dump($updateStringValueSql); $result = mysql_query($updateStringValueSql, $dbLink); if (!$result) { echo $updateStringValueSql; throw new Exception('Failed to update blind'); } }
function getRoleIdFromName($roleName) { // connect to db $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $sql = "SELECT id FROM role WHERE name = '" . $roleName . "'"; $result = mysql_query($sql, $dbLink); if ($result) { if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); $roleId = $row['id']; } } return $roleId; }
function getSeasonHunts($season) { // Connect to database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $huntList = array(); $findHuntsForSeasonSql = generateFindHuntsForSeasonSql($season); //var_dump($findHuntsForSeasonSql); $result = mysql_query($findHuntsForSeasonSql, $dbLink); $row = mysql_fetch_assoc($result); while ($row) { $oneHuntId = $row['d_id']; //echo("oneHuntId"); var_dump($oneHuntId); echo("<BR>"); $oneHunt = getHuntById($oneHuntId); //echo("oneHunt"); var_dump($oneHunt); echo("<BR>"); $huntList[] = $oneHunt; $row = mysql_fetch_assoc($result); } return $huntList; }
function getHuntsDetailsForASeason($season) { // Connect to the Database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $huntDetailsList = array(); $findAllHuntDetailsIdsSql = generateFindAllHuntDetailsForASeasonSql($season); var_dump($findAllHuntDetailsIdsSql); $result = mysql_query($findAllHuntDetailsIdsSql, $dbLink); $row = mysql_fetch_assoc($result); while ($row) { $oneHuntDetailId = createHuntDetailsFromRow($row); $row = mysql_fetch_assoc($result); } return $huntDetailsList; }
function removeAllBaselineHunts($season) { // Connect to database $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $removeBaselineHuntsSql = generateRemoveBaselineHuntsSql($season); $resultSuccess = mysql_query($removeBaselineHuntsSql, $dbLink); if ($resultSuccess) { $affectedRowCount = mysql_affected_rows(); echo "<br/><br/>" . $affectedRowCount . " Hunts Removed!</p>"; } else { echo "<br/><br/>Error deleteing: " . mysql_error() . "</p>"; } }
function loadBagCheckSpecies($birdGroup, $blindIndex, $listIndex) { // Make connection to the database. $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $speciesIndex = 0; $loadSpeciesSql = generateLoadSpeciesSql($birdGroup->getId()); //jeff_dump_string("loadSpeciesSql", $loadSpeciesSql); $result = mysql_query($loadSpeciesSql, $dbLink); $row = mysql_fetch_assoc($result); while ($row) { $newSpecies = setSpeciesInfoWithRow($row); $newSpecies->setFieldIds($blindIndex, $listIndex, $speciesIndex); $birdGroup->appendSpecies($newSpecies); $row = mysql_fetch_assoc($result); $speciesIndex++; } }