Only if $dbh is scoped to the sub. If $dbh is scoped to the file or the module, it is not disconnecting at the return from the sub.
Personally I never disconnect, which has several reasons:
- Most of my script/programs use the database from start to finish, so there is no use in disconnecting half-way through.
- Connects to remote databases is very costly, so I rather have the database handle survive as long as possible.
- Cleaning up my handles, certainly for prepared statements and cursors, should already give the server enough room to clean up for my session. Only having the session/handle open won't hurt the server too much. Note that I am using the handle, not just keeping it open to pester the server.
- I am also working with a database that has a very nasty bug in opening a new handle to the same database (for some versions of this database server). It will simply die (in very different variations of die ranging from a database crash to a script exit). As I mostly script for database-agnostic processes, I rather prevent this from happening.
Personally, I think scoped cleanup is the neatest way to manage database resources, but YMMV. The local DBA certainly should have a word in the matter.
FWIW I manage two DBD's on CPAN and am co-maint of DBI.
Enjoy, Have FUN! H.Merijn