What's The Best Way to Deal With Scripts that Interact a lot with Databases, Should I Keep a Connection Open Until the End of the Script or Open One Only When Needed?
You should only worry about opening a connection to a database when you need that connection. By allowing multiple connections to be open it can increase the chances that unwanted queries will be performed.