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

In reply to 405 error ( was: The Use of Use) by Red Neckerson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.