in reply to Establish database connection
Please excuse the lack of
use strict; use warnings;
Update:When I see this I realise just how much I have learned here at perlmonks. Perhaps I should re-write this code and re-post it.. I'll see at work on Monday morning..;)#! perl.exe #Needed for ODBC access to MSSql Database use DBI; use DBD::ODBC; $dbh = DBI->connect("dbi:ODBC:driver={SQL Server};server=SERVERNAME;da +tabase=DBNAME;uid=sa;pwd=;"); my $srv = $ARGV[0]; my $new_call_num = $ARGV[1]; $idComputer = &Get_id($srv); &Update($idComputer,$new_call_num); exit(); ##Subroutines sub Get_id { $sth = $dbh->prepare("select idComputer from Computer where Name l +ike '$srv'"); $sth->execute; $id = $sth->fetchrow; print "The Computer ID for $srv is $id\n"; return ($id); } sub Update { print "Update $idComputer with $new_call_num\n"; $sql = "update Alert set CustomField1 = ? where (idComputer like ' +$idComputer')"; $sth1 = $dbh->prepare($sql) || die $dbh->errstr; $sth1->execute($new_call_num) || die $dbh->errstr; return 1; }
|
|---|