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.
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.
Ca. Pen. Code § 2623