peacemaker1820, I had to include the IP address, Port number, and the domain\server in order to get the MS SQL to work.
Check to make sure that you have current modules as well...
PPM>install DBI
PPM>install DBD-ODBC
Here is some sample code to show you what works for my environment (W2K) but it should be similar (if not identical.)
#!/usr/bin/perl -w
use strict;
use DBI;
print "Content-type: text/html\n\n";
# Set up variables for the connection
my $server_name = 'domain\server';
my $server_ip = '1.2.3.4:port';
my $database_name = 'Tim';
my $database_user = 'Taylor';
my $database_pass = 'toolman';
my $DSN = 'driver={SQL Server};server=$server_name;tcpip=$server_ip;da
+tabase=$database_name;uid=$database_user;pwd=$database_pass;';
my $dbh = DBI->connect("dbi:ODBC:$DSN") || die "Couldn't open database
+: $DBI::errstr\n";
# Prepare the SQL query for execution
my $SQL1 = $dbh->prepare(<<End_SQL) || die "Couldn't prepare statement
+: $DBI::errstr\n";
select * FROM Test_Table
End_SQL
print '<table border="0" width="100%" cellpadding="0" cellspacing="0"
+bgcolor="#ffffff" summary=""><tr><td align="center">';
print '<table border="1" cellpadding="5" cellspacing="0" bgcolor="#fff
+fff" summary="">';
# Execute the query
$SQL1->execute() || die "Couldn't execute statement: $DBI::errstr\n";
# Fetch each row and print it
while ( my ($field1,$field2,$field3,$field4,$field5) = $SQL1->fetchrow
+_array() )
{
print "<tr><td>$field1</td><td>$field2</td><td>$field3</td><td>$f
+ield4</td><td>$field5</td></tr>";
}
print "</table></td></tr></table>";
# Disconnect from the database
$dbh->disconnect();
Also, make sure that you use:
#!/usr/bin/perl -w
use strict;
Use the search at the top for additional help on those and other topics (it's been discussed numerous times.) Also see the node:
How to RTFM it's a really good insite to finding Perl help.
HTH
- Mission
Updated: fixed my typos (again.)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.