bluegroper
Technical User
Hi forum
Newbie here, so please be gentle.
I'm trying to connect to an SQL Server using Perl (of course).
Works fine IF my SQL database name is SINGLE word.
I'd like to also connect to database name which includes space.
But rather than rename the database, I'm sure there's a better way to write my perl.
Here's the sample code snippet. This borks because of space in 'Database Name'.
TIA's for tips and clues
Newbie here, so please be gentle.
I'm trying to connect to an SQL Server using Perl (of course).
Works fine IF my SQL database name is SINGLE word.
I'd like to also connect to database name which includes space.
But rather than rename the database, I'm sure there's a better way to write my perl.
Here's the sample code snippet. This borks because of space in 'Database Name'.
Code:
#!/usr/bin/perl -w
use strict;
use DBI;
my $server=qq|SQLSERVER|;
my $database=qq|'Database Name'|;
my $user="user";
my $pass="password";
my $dbh=DBI->connect("dbi:Sybase:server=$server", $user, $pass, {PrintError=>0, RaiseError=>1});
$dbh->do("use $database");
my $sth=$dbh->prepare( "SELECT * FROM Table1" );
my $result=$sth->execute();
while($result=$sth->fetchrow_hashref) {
print "$result->{CODE}\t$result->{NAME}\n";
}
$sth->finish;
$dbh->disconnect;
TIA's for tips and clues