I tried to disable the connect and the disconnect in the sub before I looked for help here but that didnt do the job.

Looking again at sub UpdateDb, I see you have the same problem with the $Sth variable: you call prepare and finish on it, so, when the subroutine returns, the call to $Sth->fetchrow_array in the while loop is no longer valid. Here’s a suggested rewrite of the subroutine (untested):

# Update the selected Database record sub UpdateDb { my ($dbh, $upd_query) = @_; # $dbh is already connecte +d my $sth = $dbh->prepare($upd_query); # create $sth as a local, +lexically-scoped variable unrelated to the global $Sth $sth->execute() or $ErrNum = '3007'; $ErrMess = $DBI::errstr; $sth->finish(); print "HIER $ErrMess<br>" }

You would call it like this: UpdateDb($Dbh, $UpdQuery);

This is still far from ideal, as $ErrNum and $ErrMess are still being used as (effectively) global variables1. But localising $sth, by declaring it within the scope of the UpdateDb subroutine, will allow the call to $Sth->fetchrow_array in the while loop condition to work correctly.

1Strictly speaking, the only true global variables in Perl are the built-ins, such as $| and $/. Variables either declared with our or used without being declared (in the absence of use strict 'vars';) are package globals. Variables declared with my are lexicals, meaning they have lexical scope. But when I talk of “(effectively) global variables” I’m referring to the “action at a distance” problem which arises when a variable is used across so wide a scope that it becomes difficult to manage.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re^3: DBD problem by Athanasius
in thread DBD problem by Umdurman

Title:
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, details, 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, summary, 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.