sdyates has asked for the wisdom of the Perl Monks concerning the following question:

I have searched the web and many point articles point to php as the better scripting language do solve this issue. However, I know Perl is versitile and am sure it can do the job. I created a script that sends simple select quieries to the mysql database using DBI. However, I checked back later and found that the database kept opening new connections. How do I use perl to: 1) stop opening new connections and reuse previous connections 2) or at the very least close connections when a query is completed. My inner voice tells me this is a mysql question, but if one can code php to reduce connections, then why can't perl. I am up to 300 connections and that seems like too much.
  • Comment on Closing connections in mysql using perl

Replies are listed 'Best First'.
Re: Closing connections in mysql using perl
by Masem (Monsignor) on Sep 06, 2001 at 23:42 UTC
    You need to use Apache::DBI, which requires nothing but a few substitutions in your apache config and source; this will maintain a persistent connection to a database for all DBI-based perl scripts run by apache.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    It's not what you know, but knowing how to find it if you don't know that's important

Re: Closing connections in mysql using perl
by runrig (Abbot) on Sep 07, 2001 at 00:15 UTC
    Are you using mod-perl? If so read Masem's post above.
    Otherwise, are you calling $dbh->disconnect after your done with your query? It should implicitly call disconnect when the script exits, but its better to do it yourself.