Chapter 15 . Perl Development 409 I d like (Web hosting servers)
Chapter 15 . Perl Development 409 I d like to introduce the final portion of database handle creation with the DBI and MySQL DBD. The final portion is optional and consists of attributes or elements that affect the behavior of the handle itself. Therefore, adding this onto the $dbh definition I ve been using: $dbh = DBI->connect($datasource, $credentials, %elements); A number of elements are available here, most notably those that define how errors are handled and what to do with extra blank spaces for CHARcolumn types. I ll examine error handling in the next section; therefore I ll save further discussion of the optional elements until then. Up until now, I ve looked at methods for connecting to the database. By now, you have more than enough information to connect to a database. However, disconnecting from a database is important as well. Normally, when your program exits, the disconnection is automatic thus saving the programmer the work of having to explicitly issue a disconnect command. In practice, however, always explicitly disconnect your database handles. This is because there are times when using multiple handles in a program that you may need to disconnect old handles to preserve resources. If you do not issue an explicit disconnect, Perl disconnects the handle as part of the DESTROY process when a program terminates. You may see an error or warning like: Database handle destroyed without explicit disconnect This should remind you to go back and issue a disconnectstatement within your program. The syntax for the disconnect method is: $dbh->disconnect; Therefore, you can see that it is possible to disconnect only certain database handles. For example, if your program has three database handles, $dbh0, $dbh1, $dbh2, you could simply issue a disconnect() to the specific handle or handles that you no longer need. You may want to check the return status of the disconnection to make sure that it was successful. You can do this by checking the return value from the disconnect call, using the following command: $dis = $dbh->disconnect; If the value of $dis evaluates true, then the disconnection was successful; otherwise the disconnection failed.
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.