Leser: 19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/bin/perl use DBI; $dsn = 'DBI:Sybase:host=hostNameInFreeTDSconf;database=gewuenschteDB'; my $dbh = DBI->connect($dsn, "username", 'password'); die "unable to connect to server $DBI::errstr" unless $dbh; $dbh->do("use gewuenschteDB"); $query = "SELECT * FROM Session"; $sth = $dbh->prepare ($query) or die "prepare failed\n"; $sth->execute( ) or die "unable to execute query $query error $DBI::errstr"; $rows = $sth->rows ; print "$row rows returned by query\n"; while ( @first = $sth->fetchrow_array ) { foreach $field (@first) { print "field: $field\n"; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/bin/perl use strict; use warnings; use DBI; my $dsn = 'DBI:Sybase:host=myhost;port=1433;database=mydb'; my $dbh = DBI->connect($dsn, "user", 'pass'); die "unable to connect to server $DBI::errstr" unless $dbh; $dbh->do("use mydb") or die "couldn't change database"; my $query = "SELECT * FROM Session"; my $sth = $dbh->prepare ($query) or die "prepare failed\n"; $sth->execute( ) or die "unable to execute query $query error $DBI::errstr"; my $rows = $sth->rows ; while ( @first = $sth->fetchrow_array ) { foreach $field (@first) { print "field: $field\n"; } }
1
2
3
4
Global symbol "@first" requires explicit package name at test.pl line 20.
Global symbol "$field" requires explicit package name at test.pl line 21.
Global symbol "@first" requires explicit package name at test.pl line 21.
Global symbol "$field" requires explicit package name at test.pl line 22.
1
2
3
4
5
6
7
8
9
10
11
DBI connect('host=myhost;port=1433;database=mydb','user',...) failed: Server message number=4064 severity=11 state=1 line=0 server=Servername\Instancename text=Cannot open user default database. Login failed.
Server message number=18456 severity=14 state=1 line=0 text=Login failed for user 'user'.
OpenClient message: LAYER = (0) ORIGIN = (0) SEVERITY = (78) NUMBER = (34)
Server , database
Message String: Adaptive Server connection failed
at test.pl line 9
unable to connect to server Server message number=4064 severity=11 state=1 line=0 server=Servername\Instancename text=Cannot open user default database. Login failed.
Server message number=18456 severity=14 state=1 line=0 text=Login failed for user 'user'.
OpenClient message: LAYER = (0) ORIGIN = (0) SEVERITY = (78) NUMBER = (34)
Server , database
Message String: Adaptive Server connection failed
Quote...
host =item port
If you built DBD::Sybase with OpenClient 12.5.1 or later, then you can use the host and port values to define the server you want to connect to. This will by-pass the server name lookup in the interfaces file. This is useful in the case where the server hasn't been entered in the interfaces file.
$dbh = DBI->connect("dbi:Sybase:host=db1.domain.com;port=4100", $user, $passwd);