Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

connecting to postgresql with DBI

by kevind0718 (Scribe)
on Mar 20, 2008 at 21:09 UTC ( [id://675306]=perlquestion: print w/replies, xml ) Need Help??

kevind0718 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Kind and Wise Monks:

I am certain that one of your members will be able to assist me. I am attempting to connect to a postgres 8.2 database using DBI. Here are some details that may help Postgresql is install on my local machine under Windows. Within postgres in postgresql.conf listen_adresses is selected and set to *. Listen to all IP addresses?
And port is set to default 5432.
I am using Active Perl 5.8.8 with DBI 1.52 and DBD-Pg 1.45 installed.

My code follows:
use DBI; my $dsn = "dbi:Pg:dbname='benchmark_c';host='localhost'" ; my $dbname = 'benchmark_c'; my $host = 'localhost' ; my $port = '5432'; my $uname = "postgres"; my $pword = "postgres"; #** ** $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$host;port=$por +t", "$uname", "$pword"); #** ** $dbh = DBI->connect("dbi:Pg:dbname=$dbname", "$uname", "$pword" +); $dbh = DBI->connect("dbi:Pg:dbname='benchmark_c';host='localhost'", "' +postgres'", "'postgres'"); print "connected"; $stmt = $dbh->prepare("select appsyskey from appsys where upper(appsys +name) = 'LOAD LEHMAN TRADES'"); $stmt->execute(); my $rslts = $stmt->fetchrow_hashref(); my $appsyskey = $rslts->{'appsyskey'}; print $appsyskey;
Perl is actually blowing up. First time I have seen that. Makes me sad.
Your kind assistance is requested.

thanks
kd

Replies are listed 'Best First'.
Re: connecting to postgresql with DBI
by Corion (Patriarch) on Mar 20, 2008 at 21:14 UTC

    Please provide us with more exact information. We can only help you if you provide exact details:

    How did you get Perl past the TSA security check?

    How large was the area eradicated by the blast when Perl blew up?

Re: connecting to postgresql with DBI
by runrig (Abbot) on Mar 20, 2008 at 21:35 UTC
    Check out the RaiseError attribute in the DBI docs. It might give you and/or us a better idea of what is going wrong. And not that it matters here, but you might want to make a habit of adding Use strict and warnings to your programs.
      hmmm

      Doubt raise error would help because I not getting past the connect statement. It gives me the pretty dialog box or is the pretty useless dialog about sending a report to MS.

      kd
        Hi all. It seems that you have the same problem as I have on my computer. I'm currently trying to install bugzilla on my computer and I it is not working for me : It seems that the DBI->Conenct method generate an unhandled viaolation exception (0xC0000005) and so nothing can be made in order to get any data about what is happening. I'm using the following settings when calling connect. // DSN : DBI:Pg:dbname=template1;options='-c client_min_messages=warning' // USER : thedatabase // PASS : thepassword TontonYoy
Re: connecting to postgresql with DBI
by holli (Abbot) on Mar 20, 2008 at 22:53 UTC
    If blowing up means segfault, its most likely an binary incompatibility with a module; here the database driver? How did you install DBD::Pg?


    holli, /regexed monk/
      I used the Perl Package Manager
      It seems to have picked up DBD-Pg 1.45 from cpan.org/dist/DBD-Pg-1.45

      I do not know if this is good, bad or ulgy.

      Hmmm my home machine shows a different driver to be available.
      It shows DBD-PgPP ver .05.

      Which one should I use?

      thanks for your help.

      kd
        DBD-PgPP is a pure perl version...either will work (AFAIK), but the pure perl is bound to be slower. Another alternative is DBD::ODBC with the Pg ODBC driver (in the spirit of "just try different stuff until something works").

        (Update: ) Possibly helpful site seen in the CB:http://pgfoundry.org/frs/?group_id=1000199.

        Use DBD::Pg. DBD::PgPP has significant problems with placeholder substitution -- if a value contains a ?, that ? is treated as a placeholder, resulting in invalid SQL. There are two open tickets on the in RT for the module, but the module hasn't been updated since 2004.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://675306]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-19 16:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found