Guess I'm confused then. Why have three identical subroutines with three different names?
Also, The subroutines return a statement handle, yet you are not capturing any return value. That means your first fetch is fetching what? And your second fetch literally doesn't exist, how are you retrieving anything from the db for the second select statement?
You say you didn't write the script, but are trying to adjust it. I can't see where the script ever worked at all, did you leave something out?
Scott