Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2004
    Posts
    16

    Unanswered: Problem connecting PostgreSQL to Perl

    I connected postgreSQL database with perl using code given below
    But this code is working only from command prompt & when I am logged in to postgreSQL.
    But I want to view the o/p in Netscape. I am using Apache 2.0.40 & Redhat9 OS. Pls make the required modification in code. or if I have to do some enviornment setting tell me.
    I am typeing http: //localhost /cgi-bin/beers.pl in Netscape.
    Code is as follows.

    #!/usr/bin/perl
    # beers.pl - my first perl data base script!
    use DBI;
    $dbh = DBI->connect('dbi:Pg:dbname=test', 'postgres', 'post');
    $sth = $dbh->prepare("SELECT * from statename");
    $rv = $sth->execute;
    while (my @row_ary = $sth->fetchrow_array)
    {print " $row_ary[0] $row_ary[1]\n";}
    $sth->finish;
    undef $sth;
    $dbh->disconnect;
    undef $dbh;

    Regards
    amit

  2. #2
    Join Date
    Mar 2004
    Posts
    110
    I have no idea if your perl code is the right one but i know when using php you have to have your db enabled for TCP/IP connections.

    either start your db up with the -i switch or enable TCP/IP settings in your db.

    You can edit your postgresql.conf file and set:
    tcpip_socket = true

    This will allow TCP/IP connections to your db. Its dissabled by default if memory servers me correct.

    Goodluck,

    -Ed
    Another newbie postgresql user.

  3. #3
    Join Date
    Mar 2004
    Posts
    16
    I don't know how to start db with -i switch.
    can u tell me.

    Although I edit my postgresql.conf file and set:
    tcpip_socket = true
    But it is still not working :-(

  4. #4
    Join Date
    Mar 2004
    Posts
    110
    As i have no idea how things go with perl, maybe its usefull to setup php as well.
    Once you have done that, you can test if you can connect to the db with php. If you can, you know you have a problem with your perl installation or perl syntax.

    If you have tcp set true, then its automaticly turned on everytime you start up your db.

    On a side note. Im running postgresql on windows (/cygwin) and thus arent familiar with linux and stuff.

    -Ed
    Another noobie postres user

  5. #5
    Join Date
    Mar 2004
    Posts
    16
    Ur suggestions is god.
    But it is time consuming
    I don't think. I will get time for learning PHP from the scratch.

    My boss wants results.. And that too soon.
    can any body help

  6. #6
    Join Date
    Mar 2004
    Posts
    110
    Setting up php isnt gonna take that much time (30-60 min tops)
    With every download of PHP there is a good install.txt wich tells you what to do.

    It atleast gives you (and us) a good indication where your problem lies.

    Im sorry i cant be more helpfull on the perl syntax.

    -Ed

  7. #7
    Join Date
    Mar 2004
    Posts
    16
    Can any body help me with perl syntax.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •