If in a civil action or special proceeding a witness be a prisoner, confined in a state prison within this state, an order for the prisoner’s examination in the prison by deposition may be made.
1.By the court itself in which the action or special proceeding is pending, unless it be a small claims court.
2.By a judge of the superior court of the county where the action or proceeding is pending, if pending before a small claims court or before a judge or other person out of court.
Such order can only be made on the motion of a party, upon affidavit showing the nature of the action or proceeding, the testimony expected from the witness, and its materiality. The deposition, when ordered, shall be taken in accordance with Section 2622.