I assume that you mean that you print the last row, and then die with an error message when you try to fetch another row. This is exactly what I would expect if the 'RaiseError' attribute is set. If you really want to use this attribute, you could trap the error with an eval block. Exit the loop on this error. Re-throw the exception for any other error. (Refer eval)

Why are you fetching the row inside the body of the loop? Doing That is the cause of your problem.

The fetch statement (@row assignment) should be in the while loop initialization.

Why are you fetching 2 fields but only ever use the first?

You should enable RaiseError in the connection statement and not worry about using the die statement on the prepare, execute and fetch statements. If you must, you could use eval as Bill suggested to trap the errors.

After reading Chris and Ron's replies, I have to revise my previous reply. The error message that you posted is your own message from the die function on the fetch inside the loop. Right after you print your final gene_symbol, you do one more fetch. There is no data to fetch, so it returns undef. Your 'OR' interprets this as FALSE so it runs the die. I now believe that your code would run as intended if you remove the 'or' and 'die' from that fetch. ($row[0] would be undefined. You would continue to the top of the loop and exit)

I hope that this post explains your problem, but that you improve your code with the advice of the others. Good Luck, Bill

Identifying a problem is only the first step in solving it. Your success demonstrates that we have identified your original problem. You put error checking on this statement in the first place because you recognized the possibility of errors. The fact that your error test produces a false alarm at end-of-data is hardly a reason to abandon all error checking.

As long as you are working on this section of code, you may as well fix the poor practices which have been indicated. Chris gave you a reference. Have you read it? FishMonger pointed out that your SQL queries a field which you ignore. and he questioned your choice of fetch routines. You should be able to rewrite your loop to eliminate the need for one fetch outside and another inside. (Consider using 'last' to exit the loop.) Part of the reason it took us so long to identify your problem is that your error message was so poor. All of your error messages probably could be improved.

Please do not consider this issue "SOLVED" just because your code 'works' in one error-free case. Good Luck, Bill