checking connection inside loop

Ok, this idea actually makes sense but... right now running mysqlConnect() twice and mysqlConnClose() twice means there will be first opened two connections but only one closed. In other words, don't create another connection if one is already created.