Apache...::MySQL(3pm)

πŸ’– Apache::Session::Store::MySQL β€” the perl manual, but make it cute πŸ’–

okay bestie so this is Apache::Session::Store::MySQL(3pm) from the User Contributed Perl Documentation section of your man pages, and we are gonna get you fluent in it. it's giving "database goblin but make it fashion" ✨


✨ NAME ✨

Apache::Session::Store::MySQL β€” store persistent data in a MySQL database πŸ’ΎπŸŒΈ

like. that's the whole job. session data goes in, session data comes out, MySQL holds it. iconic.


✨ SYNOPSIS ✨

here's the vibe in code form, copy it exactly bestie:

use Apache::Session::Store::MySQL;

my $store = new Apache::Session::Store::MySQL;

$store->insert($ref);
$store->update($ref);
$store->materialize($ref);
$store->remove($ref);

that's the whole little lifecycle right there: insert, update, materialize, remove. slay πŸŽ€


✨ DESCRIPTION ✨

so Apache::Session::Store::MySQL fulfills the storage interface of Apache::Session. your session data lives in a MySQL database. that's it, that's the whole deal, no cap. πŸ¦‹


✨ SCHEMA ✨

bestie, you need a table. at minimum you need these columns in a table called 'sessions' β€” or, if you pass the TableName argument, whatever other table name you want, go off πŸ‘‘

id char(32)     # or however long your session IDs are.
a_session blob  # or varbinary if you plan to use a big session (>64k after serialization)

so id is char(32), unless your session IDs are a different length, in which case match that. and a_session is a blob β€” but if you're planning on a big session (over 64k after serialization, so like, a chunky one πŸ’€) then use varbinary instead.

to create this schema you can just run this command with the mysql program:

CREATE TABLE sessions (
   id char(32) not null primary key,
   a_session blob
);

and if you use some other command instead, that's fine, just make sure there's a unique index on the table's id column. no unique index = chaos, and not the cute kind πŸ™ˆ


✨ CONFIGURATION ✨

the module has to know what datasource, username, and password to use when it connects to the database. you can set these values with the options hash (peep the Apache::Session documentation for that whole situation). the options are:

  • DataSource
  • UserName
  • Password
  • TableName
  • Handle

example time, and yes it's exactly this:

tie %hash, 'Apache::Session::MySQL', $id, {
    DataSource => 'dbi:mysql:database',
    UserName   => 'database_user',
    Password   => 'K00l',
    TableName  => 'sessions'
};

instead, you can pass in an already-opened DBI handle to your database. no DataSource, no UserName, no Password β€” just hand it the handle 🫢

tie %hash, 'Apache::Session::MySQL', $id, {
    Handle => $dbh
};

✨ AUTHOR ✨

this modules was written by Jeffrey William Baker <jwbaker@acm.org> πŸ’œ (yes, "this modules" β€” that's the original wording and we respect the original wording around here)


✨ SEE ALSO ✨

  • Apache::Session

and that's the whole page bestie!! πŸ’…

this little love letter to MySQL storage came to you courtesy of perl v5.36.0, dated 2022-11-19, and the manual page formally known as Apache...::MySQL(3pm). stay hydrated, back up your blob columns, and go create that unique index πŸŒˆβ­πŸ’–

πŸ“¦ where this page comes from