Unixodbc
Jump to navigation
Jump to search
UnnixODBC is used to access a Microsoft SQL Server from Linux, we use the perl sybase DBI package to query MSSQL.
Interesting link: http://www.perlmonks.org/?node_id=392385
The follwoing packages are used:
ii unixodbc 2.2.11-16 ODBC tools libraries ii unixodbc-dev 2.2.11-16 ODBC libraries for UNIX (development files) ii freetds-common 0.82-4 configuration files for FreeTDS SQL client libraries ii freetds-dev 0.82-4 MS SQL and Sybase client library (static libs and headers) ii libdbd-sybase-perl 1.00-3+b2 Sybase/MS SQL database driver for the DBI module
This is our odbc.ini
- /etc/odbc.init
[MYSQL] Driver = /usr/lib/odbc/libtdsodbc.so Description = ODBC connection via FreeTDS Trace = No Servername = MYSQL Database = Statistic Port = 1433 #sql server default port TDS_Version = 9.0 #9.0 is sql server 2005 try domain login = yes try server login = yes nt domain = INTERN
Sample Code
use strict; use DBI; my $dsn = 'DBI:Sybase:server=MYSQL'; my $dbh = DBI->connect($dsn, "user", 'password'); $dbh->do("use Statistic"); my $sqlstat="SELECT PCC FROM tblCRSInfo"; my $sth = $dbh->prepare($sqlstat); $sth->execute; while (my($mspcc)=$sth->fetchrow_array) { print "$mspcc\n"; }