use strict; use warnings; use DBI; use Time::HiRes qw/gettimeofday/; use Win32::ODBC; my @timedata = localtime(); my $sec = $timedata[0]; $sec = '0'.$sec if $sec < 10; my $min = $timedata[1]; $min = '0'.$min if $min < 10; #check I put in place for the single digits my $hour = $timedata[2]; $hour = '0'.$hour if $hour < 10; my $day = $timedata[3]; $day = '0'.$day if $day < 10; my $month = $timedata[4]+1; $month = '0'.$month if $month < 10; my $year = $timedata[5]+1900; (my $seconds, my $ms) = gettimeofday(); $ms = ($ms-($ms%1000))/1000; my $time = $hour.":".$min.":".$sec.".".$ms; my $date = $year."-".$month."-".$day; my $temp_date = $date.' '.$time; my $server_name = 'SMOKE-SERVER'; my $database_name = 'TESTDB'; my $database_user = ''; my $database_pass = ''; my $filename = 'test_file'; my $file_date = '2011-01-01 00:00:00.000'; my $record_count = 20; my $sheet_count = 400; my $doc_ID = 12; my $client_ID = 2; my $dbh; my $DSN = "driver={SQL Server};server=$server_name;database=$database_name;uid=$database_user;pwd=$database_pass;"; eval { $dbh = DBI->connect("dbi:ODBC:$DSN"); DBI->trace(4,'C:\db_test_log88.txt'); my $sql = "INSERT INTO table VALUES ('$filename','$file_date','$record_count','$sheet_count','$doc_ID','$client_ID','$temp_date')"; my $sth = $dbh->prepare($sql); $sth->execute() or die "Execute Failed: $!"; my $last_ID = $dbh->last_insert_id(undef,undef,'table',undef) or die "No Last ID: $!"; print "Last ID inserted: $last_ID"; $dbh->disconnect(); }; if($@) { print "DB Failure: $@"; } exit 0;