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

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Why does my db query return nothing? (was: IS DBI REALLY THAT USELESS ???)
  • Download Code

Replies are listed 'Best First'.
Re: Why does my db query return nothing? (was: IS DBI REALLY THAT USELESS ???)
by dws (Chancellor) on May 07, 2002 at 02:08 UTC
    but when it reaches the point of connecting by the means of DBI it returns a BLANK page (and not a GREEN one)

    It really, really helps to check for errors on connect(). Go and do that, then report back. You might have a MySQL permission problem (such as the anonymous user not having privs to connect).

    And you probably want to move the $dbh->disconnect into get_price.

      Thank you all - after some nice guys have tested my script on THEIR server, I can say it functions !!! The drag is that my Server (where my Homepage is) didn't have "mysql"-driver installed - so, of course, there is no connection to the corresponding mysql-table. I spent one week into finding it out. Maybe one week more to convince the server of installing the thing... it's just a matter of time, I guess.
Re: Why does my db query return nothing? (was: IS DBI REALLY THAT USELESS ???)
by talexb (Chancellor) on May 07, 2002 at 04:09 UTC
    One thing I use for a sanity check is a printout of the SQL command that I'm trying to execute. If I can run the SQL from a command prompt and it returns what I expect, then I look for trouble elsewhere.

    Check your return statuses for all calls to DBI, and try to narrow down exactly where your script is having trouble. The best way for us to help you is for you to post the smallest possible code fragment that's giving you trouble.

    Und entlich, viel Gluck!

    --t. alex

    "Nyahhh (munch, munch) What's up, Doc?" --Bugs Bunny

    ps Actually, DBI is quite useful. Really. :)

Re: Why does my db query return nothing? (was: IS DBI REALLY THAT USELESS ???)
by japhy (Canon) on May 07, 2002 at 05:53 UTC
    Here's one possible problem:
    foreach (@$data){ $res = join (' ', @$_); } # should be...? foreach (@$data) { $res .= "@$_"; # same as join(" ", @$_); }

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Re: Why does my db query return nothing?
by tadman (Prior) on May 07, 2002 at 06:01 UTC
    A couple of notes first:
    • Indentation would help readability in an enormous way.
    • It's not clear why you're calling use vars for some simple globals. You can probably just declare them with my as usual, unless you are using them in other modules, which is a scary thought anyway. Maybe that is where error_page() lives? Try passing this data as arguments, such as error_page("eins","zwei")
    • Don't call your subroutines with ampersand, such as &foo, but with brackets, such as foo(). Ampersand is a Perl 4 thing and is slightly dangerous because of how it can work in Perl 5.
    • Each time through your @$data loop you are reassigning to $res. Maybe you meant to append, such as $res .= "@$_";
    • It's not clear what you expect $_ to be at the end of your program.
      Thank you all - after some nice guys have tested my script on THEIR server, I can say it functions !!! The drag is that my Server (where my Homepage is) didn't have "mysql"-driver installed - so, of course, there is no connection to the corresponding mysql-table. I spent one week into finding it out. Maybe one week more to convince the server of installing the thing... it's just a matter of time, I guess.
Re: Why does my db query return nothing? (was: IS DBI REALLY THAT USELESS ???)
by gt8073a (Hermit) on May 07, 2002 at 05:56 UTC

    Update: This is wrong, I found it somewhere else.. I was a little too trigger happy.

    It only runs ok through all the "if's" (error-pages show), but when it reaches the point of connecting by the means of DBI it returns a BLANK page (and not a GREEN one).

    You are not printing a header in in show_result.

    sub show_result { print <<"EOM" ... EOM $dbh->disconnect; }

    And

    sub error_page { print $query->header; print <<"EOM" ... EOM }

    Will perl for money
    JJ Knitis
    (901) 756-7693
    gt8073a@industrialmusic.com