use DBI;
$DB_name = 'mydb';
$DB_user = 'postgres';
$DB_pwd = '';
$dbh = DBI->connect("dbi:Pg:dbname=$DB_name","$DB_user","$DB_pwd");
if ( !defined $dbh ) { die "Cannot connect to database!\n"; }
$sth = $dbh->prepare("SELECT * FROM mytable");
$sth->execute();
while ( ($id,$name) = $sth->fetchrow_array() ) { print "$id\t\t $name \n"; }
$sth->finish();
$dbh->disconnect();
remote-host# perl pg-connect.pl
DBI connect('dbname=sysdb','postgres',...) failed: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"? at pg-connect.pl line 7
Cannot connect to database!
Thanks,
Dipti
On Wed, Mar 31, 2010 at 11:53 AM, Pavel Stehule <pavel.stehule@xxxxxxxxx> wrote:
Hello
2010/3/31 dipti shah <shahdipti1980@xxxxxxxxx>:
http://www.felixgers.de/teaching/perl/perl_DBI.html> Hi,
>
> Could anyone please provide me an example to connect to a postgresql
> database using Perl language and accessing the tables, schemas, and other
> postgresql objects.
>
http://structbio.vanderbilt.edu/chazin/wisdom/dbi_howto.html
Regards
Pavel Stehule
> Thanks,
> Dipti
>