Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Help - "fetchrow_hashref" problem

Quote Reply
Help - "fetchrow_hashref" problem
I had some problems and needed to import a backup.

Now, I get this error message when doing a keyword/keyphrase search:

A fatal error has occured:
Can't call method "fetchrow_hashref" on an undefined value at (eval 19) line 6.


Please enable debugging in setup for more details.Stack Trace======================================Links (21433): Links::environment called at /home/ohiobiz/linkssql2/admin/Links.pm line 418 with no arguments.Links (21433): Links::fatal called at (eval 19) line 6 with arguments (Can't call method "fetchrow_hashref" on an undefined value at (eval 19) line 6. ).Links (21433): Links::__ANON__ called at /home/ohiobiz/linkssql2/admin/GT/Template.pm line 759 with arguments (HASH(0x8677f9c)).Links (21433): GT::Template::_get_var called at /home/ohiobiz/linkssql2/admin/templates/default/compiled/search_results.html.compiled line 293 with arguments (GT::Template=HASH(0x867222c), premium_results, 0, 0).Links (21433): GT::Template::__ANON__ called at /home/ohiobiz/linkssql2/admin/GT/Template.pm line 539 with arguments (GT::Template=HASH(0x867222c)).Links (21433): GT::Template::_parse called at /home/ohiobiz/linkssql2/admin/GT/Template.pm line 89 with arguments (GT::Template=HASH(0x867222c), search_results.html, HASH(0x8677e94)).Links (21433): GT::Template::parse called at /home/ohiobiz/linkssql2/admin/Links.pm line 291 with arguments (GT::Template, search_results.html, ARRAY(0x8672244), HASH(0x8677e94)).Links (21433): Links::user_page called at (eval 27) line 1 with arguments (search_results.html, HASH(0x863c64c), HASH(0x8677e94)).Links (21433): Links::SiteHTML::site_html_search_results called at /home/ohiobiz/linkssql2/admin/GT/Plugins.pm line 97 with arguments (HASH(0x863c64c), [undef]).Links (21433): GT::Plugins::dispatch called at /home/ohiobiz/linkssql2/admin/Links/SiteHTML.pm line 28 with arguments (GT::Plugins, /home/ohiobiz/linkssql2/admin/Plugins, site_html_search_results, *Links::SiteHTML::site_html_search_results, HASH(0x863c64c), [undef]).Links (21433): Links::SiteHTML::display called at /home/ohiobiz/linkssql2/admin/Links/User/Search.pm line 73 with arguments (search_results, HASH(0x863c64c)).Links (21433): Links::User::Search::search called at /home/ohiobiz/linkssql2/admin/Links/User/Search.pm line 46 with no arguments.Links (21433): Links::User::Search::handle called at /home/ohiobiz/linkssql2/admin/GT/Plugins.pm line 88 with no arguments.Links (21433): GT::Plugins::dispatch called at /home/www/pages/ohiobiz/linkssql2/search.cgi line 25 with arguments (GT::Plugins, /home/ohiobiz/linkssql2/admin/Plugins, handle_search, CODE(0x80d4cec)).Help - What is this and how can I get it corrected so the search works.Thanks.mgeyman
Quote Reply
Re: [mgeyman] Help - "fetchrow_hashref" problem In reply to
I get the same error.

I would like to list all category names from the DB.
I tried the following code (used as global template tag), but I get the error code:

A fatal error has occured:
Can't call method "fetchrow_hashref" on an undefined value at (eval X) line X.

Code:
sub {
my $db = $DB->table ('Category');
my $sth = $db->select;
my ($cat, %row, $row, $name);
while (my ($row) = $sth->fetchrow_hashref) {
$name = $row{Full_Name}; # =~ s/ /_/g;
$cat = "<a href=$name>$name</a>";
}
return $cat;
}

Please help me correcting the code.
Thanks.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Help - "fetchrow_hashref" problem In reply to
Finally I solved my problem, and works fine for me, with the following corrected code:
Code:
sub {
my $db = $DB->table ('Category');
my $sth = $db->select ( ['Full_Name'] );
my ($cat, $row, $name);
while ( $row = $sth->fetchrow_hashref ) {
$name = $row->{Full_Name};
$cat .= "<a href=$name>$name</a><br>";
}
return $cat;
}

mgeyman: as you see the real difference is using:
Code:
while ( $row = $sth->fetchrow_hashref ) {
instead:
Code:
while (my ($row) = $sth->fetchrow_hashref) {
This second one is wrong, it can be only used for arrays.

I hope it helps solving your problem, too.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: Feb 24, 2002, 7:35 PM
Quote Reply
Re: [webmaster33] Help - "fetchrow_hashref" problem In reply to
Webmaster33,

Thanks for your help!

mgeyman
Quote Reply
Re: [webmaster33] Help - "fetchrow_hashref" problem In reply to
Hi,

The () shouldn't matter. When you see this, turn on debugging and look at what $GT::SQL::error says as it's most likely an SQL error. Also notice you changed your example from $db->select to $db->select (['Full_Name']). This may have been the fix.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Help - "fetchrow_hashref" problem In reply to
Hi,

I also had this problem and it came with the upgrade from 2.05 to 2.1. It was fixed for me by redoing the tables in sql because 2.1 has some new tables. The way I fixed it was to go into setup > SQL server and (WARNING) then ensure that you have the boxed checked "Create new default Links SQL tables in this database but do not overwrite any existing data." otherwise you will wipe your database. That is check the first radio button. (END WARNING)

This then creates the missing tables and seems to fix the problem for me.


Webmaster
http://www.e-bannerx.com