Red Neckerson has asked for the wisdom of the Perl Monks concerning the following question:
I am making my first stab at writing a module. In the package is a subroutine which connects up with my MySQL server, called connect. It is the standard dbi subroutine connecting up to my MySQL. I am wanting to put alot more subroutines into that module, other than just dbi connect, but because I connect and disconnect to the server in my scripts all the time, I would like just to have a module I could just call use mypackage:connect(), so I won't have to do a new subroutine in every perl file I use with mySQL.
I am using Perl DBI to MySQL. I have put my $dbh variables, such as $dbname, $dbhost, etc, just as global variables in the package, sticking out, above all the functions. I also have a disconnect function in the package file. I save the package as a pm file, properly name it, stick a .pm on it, put the 1; at the end of it. I then use the package in another perl file, use mypackage. Sure enough, I can connect to the mySQL from that script, with mypackage::connect(), and using dbi pull out rows from a table I name. Then I can disconnect from that script with mypackage::disconnect().
So far so good. However, when I try to process input from CGI.PM and insert it into the table, after a mypackage::connect() (insert into table (values) etc...., I get an error, 405. I don't know much about diagnostics or tracing errors to figure out what's wrong, but the syntax checks out okay, using -w. The same mySQL insert works fine if I just use a sub connect to the mySQL withtin that script. It just errors when I try to use connection from the module, the mypackage::connect().
Anyone have any ideas why I could access the mySQL database with a connect function inherited from a package, but not insert into the mySQL after it.
Edited 2001-05-16 by Ovid
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: The Use of Use
by Masem (Monsignor) on May 16, 2001 at 19:02 UTC | |
|
(Ovid) Re: 405 error ( was: The Use of Use)
by Ovid (Cardinal) on May 16, 2001 at 19:41 UTC | |
by Red Neckerson (Novice) on May 16, 2001 at 22:16 UTC | |
by stephen (Priest) on May 16, 2001 at 23:26 UTC | |
|
Re: The Use of Use
by converter (Priest) on May 16, 2001 at 19:33 UTC |