Skip to content

Instantly share code, notes, and snippets.

@wose
Created April 14, 2011 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wose/919078 to your computer and use it in GitHub Desktop.
Save wose/919078 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
#use Parallel::ForkManager;
use DBI;
#use Win32::OLE;
my $dbh = DBI->connect("dbi:ODBC:driver={SQL Server};server=RAPTOR\\SQLEXPRESS;uid=;pwd=;database=perltest") or die "\n\nthe mssql connection died with the following error: \n\n$DBI::errstr\n\n";
$dbh->{RaiseError} = 1;
if (defined($dbh))
{
print "Connected\n";
my ($id, $col1, $col2);
my $SQL= "SELECT id, col1, col2 FROM foobar";
my $Select = $dbh->prepare($SQL) or die "bad prepare";
$Select->execute() or die "failed execution";
$Select->bind_columns(\$id, \$col1, \$col2);
while($Select->fetch()) {
print "$id, $col1, $col2 <br />";
}
$dbh->disconnect;
}
else
{
print "Error connecting to database: Error $DBI::err - $DBI::errstr\n";
}
#PS D:\t> perl .\perltest.pl
#Connected
#1, moo, kooh <br />2, baz, bar <br />PS D:\t>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment