GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  Perl
Go To First  |  Previous Question  |  Next Question 
 Perl  |  Question 6 of 61    Print  
How to Connect with SqlServer from perl and how to display database table info?

  
Total Answers and Comments: 3 Last Update: April 09, 2007     Asked by: Mehul 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
March 17, 2006 03:45:14   #1  
siva rajesh        

RE: How to Connect with SqlServer from perl and how to...
Dear folks there is a module in perl named DBI - Database independent interface which will be used to connect to any database by using same code. Along with DBI we should use database specific module here it is SQL server. for MSaccess it is DBD::ODBC for MySQL it is DBD::mysql driver for integrating oracle with perl use DBD::oracle driver is used. IIy for SQL server there are avilabale many custom defined ppm( perl package manager) like Win32::ODBC mssql::oleDB etc.so together with DBI mssql::oleDB we can access SQL server database from perl. the commands to access database is same for any database. for furhter help needed u can mail me-Rajesh
 
Is this answer useful? Yes | No
November 17, 2006 02:05:56   #2  
madhu        

RE: How to Connect with SqlServer from perl and how to...

hi

In perl we have DBI module to connect to any database.

step1: we need to intialise the DBI module

use DBI;

step2 : connect to database using DBI module which reutrns database handle

$dh DBI->connect( dbi:mysql:database DBname username password );

step3 : to rertive data from database use select query

$sth $dh->prepare( select name symbol from table );

$sth->execute();

while(@row $sth->fetchrow_array()){

print name $row[0] symbol $row[1];

}

$dh->disconnect();


 
Is this answer useful? Yes | No
April 09, 2007 13:52:07   #3  
Rob        

RE: How to Connect with SqlServer from perl and how to...
The other trick is to use http://www.freetds.org/ for your sybase driver (M$SQL is just an old version of sybase that has been heavily modified). Then standard DBI calls work. Here is a program to login to an SQL server and print success if login is ok:

use DBI;
use DBD::FreeTDS;
$opt_u "USERNAME";
$opt_p "PASSWORD";
$opt_s "SERVERNAME:1433";

$dbh DBI->connect("dbi:FreeTDS:server $opt_s" $opt_u $opt_p);
$error $DBI::errstr;

if (defined($dbh)) {
# SUCCESS
print "Login goodn";
} else {
# ERROR
print "$errorn";
}

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape