Hello,
Fainting is a symptom of an inadequate supply of oxygen to the brain.
Fainting can occur if the vagus nerve (vagus nerve carry a wide assortment of signals to and from the brain) is stimulated.
When it is stimulated the vagus nerve slows the heart rate. This stimulation also causes nausea and cool skin. The vagus nerve can be stimulated by pain, fear and various other distresses (some people faint when they see blood or syringe). In some cases vomiting and large bowel movement can be cause of stimulation of the vagus nerve as well.
If you have difficulties when you need to go to the bathroom and you experience fainting or dizziness maybe you should mention this to your doctor just to check if there is some reasonable solution to ease your pain.