in reply to simple MySQL prob
UPDATE: As Tardis alludes to below, you might need to worry about transactions, depending on your usage. I ass-u-me'd that you'd be performing this in a similar context to mine, where I run it in an isolated environment via cron. That may or may not be the case.my $session = shift; # value we want to query for my $dbh = DBI->connect("DBI:mysql:$database:$server","$username","$pas +sword"); &extract_hash; unless ($session_hash{$session}) { &inject; } $dbh->disconnect(); sub extract_hash { my $select_query = "SELECT session FROM stats"; my $sth0 = $dbh->prepare($select_query); $sth0->execute(); while (@data = $sth0->fetchrow_array) { $session_hash{$data[0]} = 1; } } sub inject { my $insert_stmt = "INSERT INTO stats (date, time, user, session, action, type, zone) VALUES (?,?,?,?, +?,?,?)"; my $sth2 = $dbh->prepare($insert_stmt); $sth2->execute($date,$time,$user,$session,$action,$type,$zone) +; }
|
|---|