Bear Bibeault wrote:Why would you need it outside of the try block? If the code fails, is it meaningful to try and use a variable that may not be valid?
Perhaps the structure of your code is not quite right?
I am quite sure that the structure is bad
I am not quite confident with the OOP.
My exercize is:
Read line by line a csv file
Insert every line inside a mysql table
My idea is using a method to group the insert task code to avoid all the sql lines inside the while-read-file block.
bhanu chowdary wrote:But Bear, in case if the code fails we may not be doing what we do when there is a successful connection created
I'm not sure what you are trying to say. But my point is that if the purpose of the try block is to make sure that a good connection is established, why would you reference it outside of the try block where you do not know if it has been successful or not?