First as a suggestion, you might want to look at this node: What are placeholders in DBI, and why would I want to use them?. While your code as written does work, the prepare statements can be somewhat "expensive". By using place holders, you can prepare the statement(s) once and then execute them with different values. The table name can't be a variable because a prepare is a table specific execution strategy.

If you want to save the credentials for a future run of your script, you will have to have some mechanism for persistence of this data, perhaps in some table in different SQL master account? There are various security issues with this and of course you would have to handle the case where the user changes their credentials unbeknownst to your script. Perhaps other Monks have ideas on this. You could also leave your script running so the user could just keep it open in a window with a prompt for the next set of user values (without having to enter the login stuff again). I wanted to mention the place holder idea so that you can move some code out of the loop.

Update: still working on my morning coffee... Now that I re-consider this, I would re-organize the loop such that you can keep the script running in a separate window. User would exit by typing "quit", closing that window or whatever. This is an extra step for a single query, but easier for multiple queries and avoids complications with persistent storage of important security information.


In reply to Re: can one create a "session" of Perl & Mysql? by Marshall
in thread can one create a "session" of Perl & Mysql? by Anonymous Monk

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.