Can you please walk me through a coding problem? Let's say you need to develop a Python function that connects to a SQL database and retrieves data based on user input. How would you approach this task?