getMessage()); } $sql = "SELECT `AffiliateKey`, `AffiliateName`, `AffiliateCode`, `WebsiteKey` "; $sql .= "FROM `Affiliate` "; $sql .= "WHERE `AffiliateKey` = '$affiliatekey'"; $result = $db->query($sql); // Always check that $result is not an error if (DB::isError($result)) { die ($result->getMessage()); } $affiliate = new Affiliates(); if ($row = $result->fetchRow()) { $affiliate->setAffiliate_key($row[0]); $affiliate->setAffiliateName($row[1]); $affiliate->setAffiliateCode($row[2]); $affiliate->setWebsiteKey($row[3]); } $result->free(); $db->disconnect(); return $affiliate; } // // gets all affiliates // function getAffiliates($websiteKey) { $db = getConnection(); if (DB::isError($db)) { die($db->getMessage()); } $sql = "SELECT `AffiliateKey`, `AffiliateName`, `AffiliateCode`, `WebsiteKey` "; $sql .= "FROM `Affiliate` "; $sql .= "WHERE `WebsiteKey` = $websiteKey "; $sql .= "ORDER BY `AffiliateName` "; $result = $db->query($sql); // Always check that $result is not an error if (DB::isError($result)) { die ($result->getMessage()); } $affiliateArray = array(); while ($row = $result->fetchRow()) { $affiliate = new Affiliates(); $affiliate->setAffiliate_key($row[0]); $affiliate->setAffiliateName($row[1]); $affiliate->setAffiliateCode($row[2]); $affiliate->setWebsiteKey($row[3]); $affiliateArray[] = $affiliate; } $result->free(); $db->disconnect(); return $affiliateArray; } // // creates a affiliate // function createAffiliate($affiliateName, $affiliateCode, $WebsiteKey) { $db = getConnection(); if (DB::isError($db)) { die($db->getMessage()); } $sql = "INSERT INTO `Affiliate` (`AffiliateName`, `AffiliateCode`, `WebsiteKey`) "; $sql .= "Values('$affiliateName', '$affiliateCode', $WebsiteKey)"; $result = $db->query($sql); // Always check that $result is not an error if (DB::isError($result)) { die ($result->getMessage()); } $db->disconnect(); } // // updates a affiliate // function updateAffiliate($affiliateKey, $affiliateName, $affiliateCode) { $db = getConnection(); if (DB::isError($db)) { die($db->getMessage()); } $sql = "UPDATE `Affiliate` SET " . "`AffiliateName` = '$affiliateName', " . "`AffiliateCode` = '$affiliateCode' " . "WHERE `AffiliateKey` = '$affiliateKey'"; $result = $db->query($sql); // Always check that $result is not an error if (DB::isError($result)) { die ($result->getMessage()); } $db->disconnect(); } // // deletes a Affiliate // function deleteAffiliate($affiliateKey) { $db = getConnection(); if (DB::isError($db)) { die($db->getMessage()); } $sql = "DELETE FROM `Affiliate` WHERE `AffiliateKey` = '$affiliateKey'"; $result = $db->query($sql); // Always check that $result is not an error if (DB::isError($result)) { die ($result->getMessage()); } $db->disconnect(); } ?>