perl and connecting to mysql (or any) dbs

Saturday, November 6th, 2010

perl is nice and nasty because of the easy way you can ignore casting. In the case of creating an object we can run sql queries against, it’s second to none. my $db = getDB(“dbname”); my $query = $db->prepare(“SELECT COUNT(*) FROM $tblname”); my $numrows = $query->execute(); sub getDB { my $database = shift; my $username [...]

mysql to unixtime, how-to in perl

Saturday, November 6th, 2010

if you are like me you deal with perl and databases for fun and profit. At some point I needed a function to convert MySQL datetimes to unix seconds since the epoch. Here is one solution in perl: sub mysqltime2unixtime { use POSIX; my $mysqltime = shift; $mysqltime =~ m/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/; my $year = int($1); [...]


Linux versus Windows is Digg proof thanks to caching by WP Super Cache