public static function copy($params) { if (!isset($params["id"])) { throw new Exception("Missing id parameter"); } // Connect to database $mysqli = FoodAppDatabase::connect(); // Copy FOOD table record $foodFields = implode(",", array_slice(static::$fieldMap, 1)); $queryString = "INSERT into food (" . $foodFields . ") "; $queryString .= "SELECT " . $foodFields . " FROM food "; $queryString .= "WHERE id='" . $params["id"] . "'"; // Run query if (!$mysqli->query($queryString)) { throw new Exception($mysqli->error); } $newFoodId = $mysqli->insert_id; // Copy Reviews Review::copy($params["id"], $newFoodId); // Copy Components FoodComponent::copy($params["id"], $newFoodId); // Copy Recipe Steps RecipeStep::copy($params["id"], $newFoodId); // Copy Complements FoodComplement::copy($params["id"], $newFoodId); // Copy Alternates FoodAlternate::copy($params["id"], $newFoodId); }