in reply to Re: Having issues with DBI
in thread Having issues with DBI

Thanks all!

After adding the PrintErrors => 1 I now have an error message to go off of.

Can't set DBI::db=HASH(0x1ba5f4c)->{PrintErrors}: unrecognised attribute name or invalid value at C:/Perl/site/lib/DBD/mysqlPP.pm line 306

I suspect the issue is that I am using this to test to see if a value is already in a db. I am expecting empty returns and when I get an empty return I get this behavior. When I insert a test value into the db and hard code the select statement to the test value it works like a champ.

Is there a better or more correct way to go about testing for existing values in a db?

Thanks again!

Replies are listed 'Best First'.
Re^3: Having issues with DBI
by perrin (Chancellor) on Dec 11, 2008 at 18:42 UTC
    That error just says that PrintErrors is not a valid setting for DBI. It should be PrintError.

    If you want to solve this, you need to follow some of the advice you're getting. Check the return value from connect(), add strict and warnings. Also, where are you getting your @colors from? I think this is not your real code. Are you reading it from another statement handle, also stored in a variable called $sth?

      Thanks!

      Check the return value from connect(): - will do.

      add strict and warnings: Have had these on the whole time. Always good practice :) Which is why I found it so odd that it was failing silently.

      where are you getting your @colors from?: A big nasty text document. It has a few thousand entries in a semi-normalized format. One of the attributes of each entry is a pipe delimited field which is put into an array. The point though is that @color isn't from another $sth. Though I do have other $sth in the script. Is there a risk from reusing this? Something I should do to ensure this functions as expected?

      Thanks again for the help, I am a n00b when it comes to perl I am grateful for the patience and guidance.
        Reusing variables is not an issue if you no longer need the old one. I thought you might be clobbering an $sth that makes the loop run because you say that when you comment out the part that sets $sth, the loop goes through.
Re^3: Having issues with DBI
by woodpeaker (Novice) on Dec 11, 2008 at 18:30 UTC
    Well, Sometimes I m checking values like that..
    my $sth = $dbh->prepare(qq{...}); $sth->execute(); if($sth->rows){ #If handler has affected rows }
    OR
    my $sth = $dbh->prepare(qq{...}); $sth->execute(); while(my $row = $sth->fetchrow_hashref()){ #just do something if $sth +can return any records }
    There is more then one way to do (c) ))) Yuo can also try my $hash = $sth->fetchrow_hashref() || undef;