Skip to Content.
Sympa Menu

freetds - Re: SQL2000, perl, and Apache

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Mike Loomis <loomis AT Magma-DA.COM>
  • To: TDS Development Group <freetds AT franklin.oit.unc.edu>
  • Subject: Re: SQL2000, perl, and Apache
  • Date: Mon, 19 Mar 2001 20:46:42 -0500


To connect to SQL using freetds:

1.) Download DBI Perl config package
2.) Download FreeTDS and config w/ 4.2 (at least this is what
i did at the time, may support later rev's now)
3.) There is a prepackaged tar file that contains TDS and DBI
tests called: DBD-FreeTDS-0.02.tar. I don't remember where
I got it but can send it to you. It contains all the tweaking info
you will need.

Basically you do the following:

use DBI;
package TestCommon;

@EXPORT = qw(DRIVERNAME SERVER PORT USER PASSWORD);

$DRIVERNAME = "FreeTDS";
$SERVER = "server ip address";
$PORT = 1433;
$DATABASE = "database name";
$USER = "sql user name";
$PASSWORD = "passwd";

sub connect {
return
DBI->connect("DBI:$DRIVERNAME:database=$DATABASE;host=$SERVER;port=$PORT;",
$USER, $PASSWORD); }

Then from perl you do the following:

my $dbh = TestCommon->connect;

This returns a data structure of specific SQL
elements.

To query everything in the SQL database do the
following:

my $sql = "select * from $table";
my $sth;

if (!($sth = $dbh->prepare($sql))) {
print "Unable to prepared table $table.\n";
exit 1;
}

if (!($sth->execute)) {
print "Unable to execute $sql\n";
}


To read a row.

$sth->fetchrow_hash

The tar file I mentioned above is very useful....search
for that and it help.

Mike


Stephanie Shaw wrote:

> Background: Newbie. Very much so. This is only my second database I have
> tried to connect to using perl
> Problem: Need to connect to a SQL2000 database, from a *nix environment.
> My understanding is that DBI::Sybase will only work with SQL 6.x and SQL
> 7.x (please correct me if I am wrong), so I am checking into freeTDS.
> However, I have been unable to find detailed information on connecting
> using perl and freeTDS. Can someone please point me in the correct
> direction to find connection information? Or if there are suggestions on
> a better connection method than freeTDS, please advise. Thank you!
> Stephanie
>
> *Disclaimer:Views expressed are my own, and not those of Intel.
>
> ---
> You are currently subscribed to freetds as: [loomis AT Magma-DA.COM]
> To unsubscribe, forward this message to $subst('Email.Unsub')





Archive powered by MHonArc 2.6.24.

Top of Page