Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

No, that was not me that created any of those other posts. Interesting though, it looks like that person is having the same issue. Actually, that person is having the reverse of my problem. It's my Windows 7 Pro SP1 (32bit) installation that has the DBI error values working as expected, and my Vista Home Premium SP2 laptop that is not.

In any event, you raise a good point, I should have included some explicit examples along with my initial rambling.

Keep in mind, however, this is not a matter of one isolated piece of code giving me trouble. On my Win7 desktop computer, all of the DBI error reporting works properly, everywhere throughout the entire project, and on my Vista laptop, all of the DBI reporting FAILS to work throughout the entire project.

Here's some sample code. I will use the snippet I purposely messed up, that I referenced in my reply to the previous post.

my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost", $dbuid, $dbpw) || +db_err("connecting to database", $sql, $DBI::err, $DBI::errstr); my $sql = "SELECT DCredits, Price, Description FROM $dbname.CUSTOMER_P +LAN WHERE Name='$planname'"; my $sqlh = $dbh->prepare($sql) || db_err("preparing statement handle", + $sql, $DBI::err, $DBI::errstr); $sqlh->execute || db_err("executing query", $sql, $DBI::err, $DBI::err +str); while (@row = $sqlh->fetchrow_array()) { ($credits, $price, $descript) = @row; # process the data on each loop here } $sqlh->finish; $dbh->disconnect;

The actual column is really named just Credits, not DCredits.

I might not be handling the above code in the best way (feel free to let me know), but I want to catch any possible error at each point of preparation, and pass it to a subroutine db_err. It's actually a method in a little module I made for this project. The simple code for that is as follows.

sub db_err { my ($pmsg, $psql, $perrnum, $perrstr) = @_; print "<p>There was a problem: $pmsg.</p>\n"; print "<p><i>Attempted command:</i> $psql</p>\n"; print "<p><i>Error:</i> $perrnum - $perrstr</p>\n"; }

Presenting any database errors that may occur in this way is one of the requirements of the project.

To duplicate the data, here is a series of MySQL statements.

## Table CREATE TABLE `CUSTOMER_PLAN` ( `RowId` int(11) unsigned NOT NULL auto_increment, `Name` varchar(6) default NULL, `Credits` smallint(6) unsigned default NULL, `Price` decimal(8,2) default NULL, `Credit_Value` decimal(3,2) default NULL, `Status` char(1) default NULL, # A=Active, I=Inactive `Display_Order` char(3) default NULL, `Description` varchar(255) default NULL, PRIMARY KEY (RowId), KEY planname (Name), KEY descript (Description(15)), KEY dispord (Display_Order) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; ## Data INSERT INTO `CUSTOMER_PLAN` VALUES(1, 'Free', 0, 0.00, 0.75, 'A', + '001', 'Try us out - receive 3 free recipes.'); INSERT INTO `CUSTOMER_PLAN` VALUES(2, 'Shine', 12, 9.75, 0.75, 'A', + '002', 'Shine with a small introduction to Vibrant Healthy Living.') +; INSERT INTO `CUSTOMER_PLAN` VALUES(3, 'Seeker', 35, 18.75, 0.75, 'A', + '003', '<i>-noun.</i> An adventurous person who is seeking new exper +iences and new information to create a higher level of understanding +and enlightenment.'); INSERT INTO `CUSTOMER_PLAN` VALUES(4, 'Sage', 60, 47.00, 0.75, 'A', + '004', '<i>-noun.</i> A generous, lively person on the journey for t +he possession of wisdom and experience. This person is energetic, vib +rant and famed for health and wisdom.'); INSERT INTO `CUSTOMER_PLAN` VALUES(5, 'Guru', 120, 89.00, 0.75, 'A', + '005', '<i>-noun.</i> A divine teacher. This person has vast knowled +ge and practices vibrant living while sharing with their community to + create a greater understanding and manifestation of truth and beauty +.');

The versions I am using on both desktop and laptop: ActiveState Perl v5.12.4, Apache v2.2.17, MySQL v5.5.8, DBI v1.616, DBD::mysql v4.018.

Using the above back in my project, I get the following on my Win7 desktop computer.

There was a problem: executing query. Attempted command: SELECT DCredits, Price, Description FROM hlr.CUSTOM +ER_PLAN WHERE Name='Free' Error: 1054 - Unknown column 'DCredits' in 'field list' ...

etc. for the other rows. Clearly passing on what the error was.

On my Vista laptop, I get the following.

There was a problem: executing query. Attempted command: SELECT DCredits, Price, Description FROM hlr.CUSTOM +ER_PLAN WHERE Name='Free' Error: - ...

etc. No error information at all.

In reply to Re^2: DBI fails to return an error code by djten
in thread DBI fails to return an error code by djten

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (5)
    As of 2017-02-28 02:42 GMT
    Find Nodes?
      Voting Booth?
      Before electricity was invented, what was the Electric Eel called?

      Results (395 votes). Check out past polls.