You can save an array into a database field in different ways
- Serialized form
- Comma-Separated string
- JSON
(Read more about JSON data type here)
But it is not the proper solution for your problem. You should consider a workaround as given below:
Usually, a single prescription can have multiple medicines. Therefore a One to Many relation is there.
It is recommended that you create two tables as prescriptions and prescription_medicines, and save the prescription details in the prescriptions table and then add each medicine in a prescription as a row in the prescription_medicines table.
The table structure can be something as shown below.
prescriptions table
id (primary_key), doctor_id, patient_i`, date, .....
prescription_medicines table
id, prescription_id, medicine_id, dosage, ...
Here the prescription_id is the primary_key of prescriptions_table
and the medicine_id should be a primary_key of medicines_table
Now we can relate the prescriptions with medicines table.
EXAMPLE QUERY: To get the prescribed medicines and its dosage for a patient having patient id 123
SELECT med.name, pres_med.dosage
FROM prescriptions AS pres
JOIN prescription_medicines AS pres_med ON pres_med.prescription_id = pres.id
JOIN medicines AS med ON med.id = pres_med.medicine_id
WHERE pres.patient_id = 123;
-- ADD YOUR OWN LOGIC TO GET THE LASTEST/RELEVANT PRESCRIPTION