Forum Moderators: coopster & phranque

Message Too Old, No Replies

perl dbi question - getting some values out of mysql

         

jeremy goodrich

1:40 am on Mar 9, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't get this to work (it's the syntax from another script) I'm rewriting it to make it better, but still very unfamiliar with the workings of sql and the perl dbi.

Here's the code:
[perl]
($var1, $var2, $var3, $var4, $var5, $var6) = $DBIgetAllEntries->fetchrow_array;
return %fields if $DBIgetAllEntries->errstr;
%fields = (
'var1' => $var1,
'var2' => $var2,
'var3' => $var3,
'var4' => $var4,
'var5' => $var5,
'var6' => $var6,
);
return %fields;
[/perl]

amoore

2:20 am on Mar 9, 2002 (gmt 0)

10+ Year Member




what's the problem with it? Does it give an error of some kind? are you running it under "-w" and "use strict"? Does it just not return any values? perhaps that errorstring statement is true and it's returning %fields which is undefined. Maybe you should return or print that error string to see what the problem is. Is it returning from the second "return" statement, but you can't get any data out?

A little more information would help a lot.

-Andy

jeremy goodrich

2:29 am on Mar 9, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not getting anything back, or it is hanging for ever...and yes, using strict and -w :)

here is the whole subroutine it's from :
[perl]sub getFields {
my $entryNumber = shift @_;
my %fields = ();
my($url, $title, $description, $keywords, $density, $checksum, $stale);
my $DBIgetAllEntries = $database->prepare("SELECT * FROM searchTable") or return 0;
$DBIgetAllEntries->execute;
($url, $title, $description, $keywords, $density, $checksum, $stale) = $DBIgetAllEntries->fetchrow_array;
return %fields if $DBIgetAllEntries->errstr;

%fields = (
'url','$url',
'title','$title',
'description','$description',
'keywords','$keywords',
'density','$density',
'checksum','$checksum',
'stale','$stale',
);
return %fields;
}
[/perl]

I'm really only interested in the url, title, description, keywords, and density variables...the other two I dont' need.

This subroutine is for a site search engine, and the %getfields hash is used to parse out the data and return matches for the search portion of the application.

:)

amoore

4:29 am on Mar 9, 2002 (gmt 0)

10+ Year Member



How big is that table? You're doing a "select *" on it, so it could potentially be running out of memory. Or, there could be nothing in the table, so that's what you get back. Also, as long as you're just returning one row, is there any reason to pull the whole table out with the statement? Perhaps you should do a "limit 1" to it at least if you don't care which row you get.

The difference between not getting anything back and hanging forever is pretty significant. Is the function returning or isn't it?

jeremy goodrich

3:39 pm on Mar 9, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



nope, it's not returning anything at this point....

the sub routine is used to pull all the fields out of the searchable part of the database, to then use within the script to find matches.