Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

connect database

by Bass-Fighter (Beadle)
on Jan 08, 2009 at 12:36 UTC ( [id://734867]=perlquestion: print w/replies, xml ) Need Help??

Bass-Fighter has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

this piece of my code doesn't work... who knows in what I must change this to get it work? because I can't see it...

use DBI; my$dbh = DBI->connect("DBI:Pg:dbname='five'; port=5432", user=postgres +,{ RaiseError => 1, AutoCommit => 0 }) or die "kon de database niet openen!";
I am getting every time the same error...
this one: Can't modify constant item in scalar assignment at geheeldb.txt line 9, near "postgres,"

this database has no password, so that isn't the problem ;)

Replies are listed 'Best First'.
Re: connect database
by ikegami (Patriarch) on Jan 08, 2009 at 12:56 UTC
    • Don't hide errors. Use use strict; and use warnings;.

    • user=postgres

      should be

      'postgres'

      As is, it means

      'user' = 'postgres'

      and it doesn't make sense to assign to a constant string.

    • You have an argument missing. While the option hash is optional, the password isn't. It must appear between the user name and the option hash, even if it's only ''.

    • I don't think quotes are allowed around the dbname. They're definitely not needed.

      "DBI:Pg:dbname='five'; port=5432"

      should be

      "DBI:Pg:dbname=five;port=5432"
    • ... or just

      "DBI:Pg:dbname=five"

      since port 5432 is the default.

    Update: Added last two bullets.

      this is only the piece of the error, there is more, so I use strict.

      I now changed it into this:

      #!usr/bin/perl use 5.6.1; use strict; use warnings; use DBI; my$dbh = DBI->connect("DBI:Pg:dbname=five; port=5432", 'postgres', '', +{ RaiseError => 1, AutoCommit => 0 }) or die "kon de database niet openen!";

      and now I get this:
      DBD::Pg::db do failed: ERROR: parser: parse error at or near "voor" at character 94
      DBD::Pg::db do failed: ERROR: parser: parse error at or near "voor" at character 94

      and what is the meaning of that?

        DBD::Pg::dbdo failed: ERROR: parser: parse error at or near "voor" at character 94

        So it worked, cause you made it to some $dbh->do call further down.

Re: connect database
by marto (Cardinal) on Jan 08, 2009 at 13:01 UTC

    From the DBD::Pg documentations section on the connect method:

    "The following connect statement shows almost all possible parameters:"

    $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$host;port=$port;optio +ns=$options", $username, $password, {AutoCommit => 0, RaiseError => 1, PrintError => 0} ); );

    So try:

    my$dbh = DBI->connect("DBI:Pg:dbname=five;port=5432", 'postgres', '', { RaiseError => 1, AutoCommit => 0 }) or die "kon de database niet ope +nen!";

    Update: Changed wording of the opening sentence.

    Update 2: Added blank password, thanks erix

    Hope this helps

    Martin

      yes it worked ;) I get now a new error of something else so I can now look at it.
Re: connect database
by JavaFan (Canon) on Jan 08, 2009 at 12:46 UTC
    You want 'postgres' as the second argument. (With quotes)

      well, that is acactly my problem, if I don't use quotes, use single quotes or double quotes... It doesn't matter :S

      look:
      with double quotes:
      Can't modify constant item in scalar assignment at geheeldb.txt line 9, near ""postgres","

      with single quotes:
      Can't modify constant item in scalar assignment at geheeldb.txt line 9, near "'postgres',"

      with no quotes at all:
      Can't modify constant item in scalar assignment at geheeldb.txt line 9, near "postgres,"

        I said, use 'postgres' as the second argument. I did not say to use user='postgres' as the second argument.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-03-28 11:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found