#!/usr/bin/perl use DBI; use S::Utils qw(setOracleEnv); use strict; use warnings; # Declare variables my $DBNAME = "calendar"; my $DBTABLE = "libhourstest"; my $csvfile = "all_dates.csv"; # -- call sub to set Oracle env so script can run as cronjob &setOracleEnv; #connection info for db my ($dsn,$dbun,$dbpass) = ( 'dbi:mysql:calendar:localhost:', '', '' ); # -- connect to db my $dbh = DBI->connect( $dsn,$dbun,$dbpass, { AutoCommit => 0, RaiseError => 0, PrintError => 1 } ) || die $DBI::errstr; ### Get rid of the old records in the web content db table $dbh->do (qq{ delete from libhourstest }); my $update_h = $dbh->prepare(qq{INSERT INTO $DBTABLE (libhours_id, ymd, dow, opening, closing, is_closed) VALUES (?, ?, ?, ?, ?, ?)}); open my $ih, $csvfile or die "Can't open file, $csvfile: $!"; while (<$ih>) { chomp; my @rows = split ','; # A comma is the delimiter my $libhours_id = $rows[0]; my $ymd = $rows[1]; my $dow = $rows[2]; my $opening = $rows[3]; my $closing = $rows[4]; my $is_closed = $rows[5]; $update_h->execute($libhours_id, $ymd, $dow, $opening, $closing, $is_closed) or die $dbh->errstr; } my $res = $dbh->selectall_arrayref( q( SELECT libhours_id, ymd, dow, opening, closing, is_closed FROM libhourstest)); foreach( @$res ) { print "\n$_->[0], $_->[1] $_->[2] $_->[3] $_->[4] $_->[5]\n\n"; } END { $dbh->disconnect if $dbh }