The city attorney shall be the legal advisor of the city and all its officers in all matters arising and in which legal proceedings may be taken; he shall prosecute all suits, actions and proceedings instituted on behalf of said city and defend all suits and actions against said city, and, when requested in writing, shall give his written opinion to the mayor, council, or any standing committee thereof, upon such legal questions as may be referred to him affecting the city’s interests; he shall perform such other duties as may be required. It shall be his duty to attend sessions of the police court, when requested by the mayor or police judge, and prosecute all trials therein and all appeals that are taken from such court; and for his services he shall receive such compensation as the council shall provide.