Imagine this scenario: you company is running a sql server which is only accesible from your LAN, you cannot use NAT, so you need to acces from you webserver you sql server and show some information.... Then this is the solution to your scenario, there are a few steps you would need to make before star coding:
1.- if you don't have freetds, then download and install freetds you can get it from http://www.freetds.org/
2.- then you would need to go to cpan (search.cpan.org) and downlaod and install perl sybase module, this url might help http://www.linuxjournal.com/article/5732
3.- Then you are ready to query any sql sever as long as you have all ports opened on you LAN to your sql server.
Question are welcomed.. so don't hesitate in contacting me..
Nov 27, 2006
Perl and Mysql
You might wonder how to make perl work something similar to php or even asp when querying DB, well here is a code that might help you.
Php as well as asp they allow you to call fields from a record set in the way $rs['field_name'] and perl some times seem to be verydifucult... then this might change your point of views. take a look a t this:
#!/usr/bin/perl
use CGI;
use DBI;
$dbname = "";
$host = "";
my $db = 'DBI:mysql:$dbname:$host';
my $username = 'user';
my $pass = 'password';
my $dbh = DBI->connect($db, $username, $pass);
my $sql = "SELECT * FROM categoria";
$sth = $dbh->prepare($sql);
$sth->execute() or die "Error";
my($count) = $sth->rows();
print "Records: $count\n";
my %row;
$sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } ));
while ($sth->fetch) {
foreach $key (keys (%row)){
print "\$$key - $row{$key} ** ";
}
print "\n";
}
$sth->finish;
$dbh->disconnect();
exit;
This will code will let you call record set field streight from the query.. supose you have a field name id then you can cal $row{'id'} within the foreach loop.
Hope this is usefull, comments are welcomed..
Php as well as asp they allow you to call fields from a record set in the way $rs['field_name'] and perl some times seem to be verydifucult... then this might change your point of views. take a look a t this:
#!/usr/bin/perl
use CGI;
use DBI;
$dbname = "";
$host = "";
my $db = 'DBI:mysql:$dbname:$host';
my $username = 'user';
my $pass = 'password';
my $dbh = DBI->connect($db, $username, $pass);
my $sql = "SELECT * FROM categoria";
$sth = $dbh->prepare($sql);
$sth->execute() or die "Error";
my($count) = $sth->rows();
print "Records: $count\n";
my %row;
$sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } ));
while ($sth->fetch) {
foreach $key (keys (%row)){
print "\$$key - $row{$key} ** ";
}
print "\n";
}
$sth->finish;
$dbh->disconnect();
exit;
This will code will let you call record set field streight from the query.. supose you have a field name id then you can cal $row{'id'} within the foreach loop.
Hope this is usefull, comments are welcomed..
Perl old but usefull
I amazing how old programming languages as perl still exist and they have proven to be very usefull.
When I first started programming in perl, I thouhgt it was a tough language and that it was not usefull at all, now a days I have discovered that is extremely powerfull and easy to use (if you have programmes in c++ or c, or something similar) I have used it for server maintenance scripts and related tasks as well as web programming. On the long run I have discovered that perl tends to be a little slow and messy for websites so I have moved to PHP, I think asp is to dump for web, so I rather use php or somethign similar.
Its amazing how perl can do a lot of thing that with java would take a lot of time, lets say open a file, with perl you just execute the command:
open(file_handler,"filepath/filename") or print "error\n\n";
on the other hand asp, or java you need to create an instance then open, let't not mention reading a file.
As far as I have used perl, I can say perl is fantastic, and that it will stay for a while.. for more information about perl you can visit cpan.org, perlmonks.org and some other perl related links. in this blogss I will be posting a few codes from perl script I have made and explanning them.
comments are welcome.
Greeting.
When I first started programming in perl, I thouhgt it was a tough language and that it was not usefull at all, now a days I have discovered that is extremely powerfull and easy to use (if you have programmes in c++ or c, or something similar) I have used it for server maintenance scripts and related tasks as well as web programming. On the long run I have discovered that perl tends to be a little slow and messy for websites so I have moved to PHP, I think asp is to dump for web, so I rather use php or somethign similar.
Its amazing how perl can do a lot of thing that with java would take a lot of time, lets say open a file, with perl you just execute the command:
open(file_handler,"filepath/filename") or print "error\n\n";
on the other hand asp, or java you need to create an instance then open, let't not mention reading a file.
As far as I have used perl, I can say perl is fantastic, and that it will stay for a while.. for more information about perl you can visit cpan.org, perlmonks.org and some other perl related links. in this blogss I will be posting a few codes from perl script I have made and explanning them.
comments are welcome.
Greeting.
Subscribe to:
Posts (Atom)