When I last looked DB connections could not be serialised for saving them to a file for later use. So, saving your connection for later, to a file and exiting your program will not work unless some sort of serialisation of the connection becomes possible.

Then you have the "Service" model (Re: can one create a "session" of Perl & Mysql?) or the "daemon" model, I add.

In either of these, you could use connection pooling. The first time a user appears (or re-appears after a long time interval) they give credentials and a connection is created for them waiting in the pool, possibly associated with a cookie the user saves on their side in order to get exact same connection the next time. But it means that you have to mediate all your DB queries through the service/daemon which will slow things down. But it has a benefit: you can restrict DB access to only a few formalised queries. For example: query1: it only accepts an AGE field and gets back 20 results max. query2: ... etc. So, doing it this way you will need to write 2 programs: the service/daemon and the client. Quite insecure if external access is allowed because it relies on user presenting a cookie for access to DB. But then isn't everything cookie-driven nowaday?

It is possible to connect to mysql without providing credentials by creating a profile (see mysql_config_editor, search for passwordless mysql) and pointing mysql every time you need access, to the profile data file. Can this be achieved via Perl DBI? I don't know.

You could save the credentials to a file (VERY INSECURE) to be read next time the same user requests DB access. I will not describe this any further because it's twice as wrong as it's practical.

I am just thinking out loud, bw bliako


In reply to Re: can one create a "session" of Perl & Mysql? by bliako
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.