Even though opioids are prescribed by a doctor, using them in any way other than prescribed, even occasionally, is dangerous. The way prescription opioids affect your brain is the same as heroin, making them both risky and highly addictive.
While opioids are prescribed for certain short-term pain, the CDC (Centers for Disease Control and Prevention) states that 3 days or less of opioid treatment is usually enough, while opioid use for more than 7 days is rarely needed nor effective.