Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Error messages from DBI

by nbierman (Novice)
on Jun 12, 2008 at 16:38 UTC ( [id://691715]=perlquestion: print w/replies, xml ) Need Help??

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

I just installed Strawberryperl 10.0.1 on windows xp and I am trying to connect to Oracle. My code looks like this
#! /usr/bin/perl use DBI; use strict; use warnings; print "Hello.\n"; my $dsn = 'dbi:Oracle:sid=ORCL'; my $user = 'MyID'; my $password = 'MyPWD'; my $dbh = DBI->connect($dsn,$user,$password,RaiseError => 1, AutoCommi +t => 0) || die "Database connection failed: $DBI::errstr"; print "Database connection succeeded.\n"; $dbh->disconnect(); print "Bye, bye ;-)\n"; exit
When I run the script I get the "Hello" message, and 2 perl messages. Can't use string ("1") as a HASH ref while "strict refs" in use at ../strawberry/perl/site/lib/DBI.pm line 560. DBI->connect using 'old-style' syntax is deprected and will be in error in future versions at DBITest.prl line 24. I'm not too concerned about the syntax message, but obviously the first message is a showstopper. Can somebody help me out with the message from DBI.pm and, if possible, point me to some documentation on the 'new-style' syntax? Thanks

Replies are listed 'Best First'.
Re: Error messages from DBI (\%attr)
by kyle (Abbot) on Jun 12, 2008 at 16:42 UTC

    Look closer at the example in the DBI documentation. Your connect() would probably work this way:

    my $dbh = DBI->connect($dsn,$user,$password, { RaiseError => 1, AutoCommit => 0 }) || die "Database connection failed: $DBI::errstr";

    The last argument is a hash reference. If you're not familiar with references, have a look at perlreftut and perlref. After that, maybe References quick reference.

    Update: Also, since you're using RaiseError, you don't need to die explicitly. DBI will do that for you if there's a problem.

      I changed the connect() to this: my $dbh = DBI->connect($dsn,$user,$password) or die $DBI::errstr; That gets me past the syntax warning and the HASH error. Now Perl can't find DBD/Oracle.pm, but that's a different issue. Thanks for your help.

        You do realize that you've not turned on the RaiseError and not turned of AutoCommit, right? Read the parent again, you'll want to use his syntax -- all you were missing was a pair of braces.

        <radiant.matrix>
        Ramblings and references
        “A positive attitude may not solve all your problems, but it will annoy enough people to make it worth the effort.” — Herm Albright
        I haven't found a problem yet that can't be solved by a well-placed trebuchet

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 19:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found