This article illustrates how to setup a development environment using Perl and SQL Server on the following platforms: Microsoft Windows, Red Hat Linux, and Sun Solaris. Step by step, you can learn, and may choose, the best way that fits into your own requirements.
Installing and configuring Sybase Adaptive Server is also as easy as MS SQL Server.
If you want to use MS SQL Server as a database, install MS SQL Server 7.0 with service pack 2.
Perl uses DBI/DBD architecture to access databases (DBI means Database Interface, DBD means Database Driver). With a specific DBD driver installed, Perl can use the same DBI API to support different database systems.
The DBI module is already installed with the ActivePerl distribution itself. In order to support SQL Server, we need to download the SQL Server DBD driver from cpan.org: www.cpan.org, search for the DBD-Sybase module, and download the latest version 1.01 source code: DBD-Sybase-1.01.tar.gz
Note: there are a few other DBD Drivers that support both Sybase and Microsoft SQL Server on Windows, such as DBD::ADO; however, they can only be used on a Windows platform.
In order to compile and install the DBD::Sybase source code, we need a C compiler installed on Windows (I use Microsoft Visual C++ 6.0), and make sure nmake.exe is available in the PATH.
Use a decompression utility (ie: Winzip) to extract DBD-Sybase-1.0.1.tar.gz to any available drive such as C:. You should now have the folder c:DBD-Sybase-1.01 that holds all the source code.
Change directory to the above folder, and issue the following command in the command prompt window:
You may receive a warning message, such as missing the following library: libtcl.lib, libcomn.lib and libintl.lib.
Because we are using the Sybase CT-Library, libcs.lib and libct.lib are mandatory; others are optional, and we can ignore this warning. Sybase removes these static libraries from its version 12.5 of the Adaptive Server package. The run time libraries still do exist (ie: libtcl.dll, libcomn.dll, linintl.dll) See the following screenshot:
If you receive an error message other than the one above, please check the following environment variable: SYBASE and SYBASE_OCS %SYBASE% should equal the directory root where Sybase Adaptive Server is installed (ie: C:sybase) and %SYBASE_OCS% should equal OCS-12_5 for Sybase Adaptive Server 12.5
Issue the following command to compile the source code:
Then install the package by issuing this command:
Using the following code, we can list all the DBD drivers we’ve installed with Perl:
use strict; use DBI; my @drivers=DBI->available_drivers(); print join("n",@drivers); print "n";
Copy and paste the above code in notepad, and save the file as dbi_drivers.pl.
Issue the following command in the command prompt window:
See following screenshot:
I recommend you download PerlIDE from open-perl-ide.sourceforge.net, it is a free and open source tool. You can download the precompiled application and install it easily on your Windows operating system. With PerlIDE, you can debug and track variables in your Perl applications.