http://www.perlmonks.org?node_id=1056309


in reply to Re^4: MSSQL/Perl

UPDATE: appologies, I thought the post I was responding to was the first post and only just realised it was in the middle of the thread.

You've given us so little context so I'll have to assume you already know you want to use an ODBC.

DBI provides a single interface to multiple DBDs (DataBase Drivers). Most DBDs only support one database backend (e.g., DBD::Oracle only talks to Oracle, DBD::Pg only talks to postgres) and are usually built against a database supplied client library.

DBD::ODBC is an interface between DBI and the ODBC API so not just one database as many databases have ODBC Drivers. DBD::ODBC needs to link with an ODBC Driver Manager (unixODBC or the MS ODBC Driver Manager). When you use an ODBC Driver in perl:

So, to use DBD::ODBC you need to install a) unixODBC and b) an ODBC driver. The unixODBC packages you need are often called 'unixodbc' and unixodbc-dev. Then you'll need to get hold of the ODBC driver for your database, install that and tell unixODBC about it (usually by settings in an /etc/odbcinst.ini file.

Replies are listed 'Best First'.
Re^6: MSSQL/Perl
by tma2620 (Initiate) on Oct 02, 2013 at 15:25 UTC
    below is my code and the error, data retrieval part not included. I am on solaris 10 machine running perl 5.8.0. The default installation does not have DBD::ODBC so I downloaded and installed in my local library. I guess it is some kind of version conflict...pls help
    #!/opt/perl/5.8.0/bin/perl use lib "/home/myhome/lib"; use DBI; use DBD::ODBC; @ary = DBI->installed_drivers; print "@ary"; my ($data_source, $database, $userid, $password) = qw( db_1:blah.pp.ns.net;5000 db_1 read readP); my $connect_string = "driver={SQL Server};Server=$data_source;Database +=$database;UID=$userid;PWD=$password"; my $dbh = DBI ->connect ( "$connect_string" ) or die $DBI::errstr; my $sql = "select getdate()"; my $sth = $dbh->prepare ( $sql ); $sth->execute; $dbh->disconnect ();
    below is the error I get.
    DBI version 1.609 required--this is only version 1.35 at /opt/perl/5.8 +.0/lib/Exporter/Heavy.pm line 221. Compilation failed in require at mssql.pl line 4. BEGIN failed--compilation aborted at mssql.pl line 4.

      You should read about code tags when submitting a post here. The error "DBI version 1.609 required--this is only version 1.35" seems fairly straight forward to me. You are using a DBD::ODBC version that requires DBI 1.609 and you've only got DBI 1.35. Either upgrade DBI then rebuild DBD::ODBC or downgrade DBD::ODBC (the former is better in my opinion).

        my home library which I am using in the code has the latest DBI and DBD:ODBC. How can I override the old installation of DBI which is getting picked up from the common repository.  use lib "/home/myhome/lib";