The district attorney must attend before the grand jury when required by them, and he may do so whenever he sees fit for the purpose of examining witnesses in their presence or giving them legal advice as to any matter connected with their duties; and he may appear before them at any time to give information as to any matter cognizable by them, but he must not be present at the expression of their opinions or the giving of their votes on any matter before them.