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

Hi everyone,
I'm getting a fetchrow() called without execute() at line... for this forum I partially completed and I was told that selectrow() would fix this problem, I'm not familiar completely with MySQL or DBI, so I was wondering if I could get a hand. My code is on my pad, if you'd like to take a look.
Thank you in advance.
-Dhoss

And if you're feeling lucky... come and take me home And if you feel loved If you feel lucky, if you feel loved If you feel lucky, if you feel loved You've crossed the walls - Excelled Further along through their hell All for my heart, I watch you kill You always have, you always will Now spread your wings and sail out to me....

Replies are listed 'Best First'.
Re: DBI help->selectrow_hashref instead of fetchrow_hashref?
by rnahi (Curate) on Jul 06, 2003 at 09:33 UTC

    As others have said, you posted the wrong code.

    However, even if you'd posted the correct code, posting the whole script is not the right way to get help.

    You should make a test script containing only what is not working for you, and we could have a better view of your problem.

    Please read carefully Before asking a database related question ... and ask again.

Re: DBI help->selectrow_hashref instead of fetchrow_hashref?
by Limbic~Region (Chancellor) on Jul 06, 2003 at 12:46 UTC
    dhoss,
    I do not want to sound like I am harping, but you should always make your node self-contained if possible. Referring to code on an external site or to a temporary location like your scratch pad will make the node useless in the future if that content changes. If it is a great deal of code, try to break it down to the smallest reproducible problem. If that is still too big, enclose them in readmore tags.

    Cheers - L~R

      Ahhh, yes, ok, well, I have the updated code on now, sorry, I'm in a rush. Gotta go and thanks again.

      And if you're feeling lucky... come and take me home And if you feel loved If you feel lucky, if you feel loved If you feel lucky, if you feel loved You've crossed the walls - Excelled Further along through their hell All for my heart, I watch you kill You always have, you always will Now spread your wings and sail out to me....
Re: DBI help->selectrow_hashref instead of fetchrow_hashref?
by archon (Monk) on Jul 06, 2003 at 06:05 UTC
    i don't see any DBI code in your pad.. selectrow() isn't a DBI method either. check the DBI manpage for the proper methods. fetchrow() is typically called after you execute() a select statement. the selectrow_* methods do all of that for you and shove the returned information into the requested data stucture.
Re: DBI help->selectrow_hashref instead of fetchrow_hashref?
by eric256 (Parson) on Jul 06, 2003 at 06:13 UTC
    Do you have the wrong code on your pad? I couldn't find any user of DBI let alone fetchrow.... Let me know if i'm just way off base here. Either way i would check the query that you are trying to do a fetchrow() on and make sure that you have called execute on it before you try to fetchrows. selectrow_hashref() and selectall_hashref() just automate the process of prepareing, executing and fetching the rows. They normaly make very nice alternatives so that it all happens in one call, but i am sure there are some cases where fetching one record at a time is better.

    Good Luck,
Re: DBI help->selectrow_hashref instead of fetchrow_hashref?
by perrin (Chancellor) on Jul 07, 2003 at 20:01 UTC
    I looked at your updated code. I don't see anywhere that you failed to call execute(), but I also don't see where you're getting $dbh from.

    Switching to selectall_hashref() is possible and may get rid of the error if you properly remove the other DBI calls that it replaces, but it doesn't solve the fundamental problem which is that you're trying to write DBI code but you haven't taken the time to learn the basics of DBI yet. You should start with this tutorial and then have a look at the DBI docs. Copy-and-paste coding is a dangerous thing to do with DBI.

      Thanks a bunch, perrin. I truly haven't taken time to learn my DBI basics, so I'll definitely check that tutorial out and keep it for reference. select_all, that's what I was looking for!
      -Dhoss

      And if you're feeling lucky... come and take me home And if you feel loved If you feel lucky, if you feel loved If you feel lucky, if you feel loved You've crossed the walls - Excelled Further along through their hell All for my heart, I watch you kill You always have, you always will Now spread your wings and sail out to me....