[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] perl db question, problems when modifying admin
Quoting Doug Alcorn (lathi@seapine.com):
>
> Mike Heins <mheins@redhat.com> writes:
>
> > > Are those functions the sameones as perl's DBI ?
> >
> > No. But you can get a DBI object with $Sql{table}.
>
> I've had problems with this that I can't explain. I've tried code
> list this:
>
> [mvasp tables="products"]
> my $phone = $Scratch->{item_code};
> my $dbh = $Sql{products} or return "bad DB handle";
> my $sth = $dbh->prepare("select * from products where sku='$phone'") or
> return "Can't prepare select";
> my $rv = $sth->execute();
> return "Can't execute select" unless $rv;
> my $names = $sth->{'NAME'};
> my $numFields = $sth->{'NUM_OF_FIELDS'};
> my $rowdata = $sth->fetchrow_arrayref();
> HTML "row: $rowdata names: $names num: $numFields";
> [/mvasp]
>
> What outputs from this is "row: names: ARRAY(0xXXXXXXX) num: 32".
> Note that the $rowdata is blank. Of course, what I'm really wanting
> to do is use $sth->fetchrow_hashref(). However, that presents a
> problem too. My catalog's error.log reports:
>
> 216.23.11.254 YnvnhZCY:216.23.11.254 - [18/February/2002:09:47:41 -0600] digicel /ic/mot-200.html Safe: Can't locate DBI object method "fetchrow_hashref" via package "DBD::mysql::st" at (eval 284) line 15.
>
It should be wrapped and work on all later versions of IC, but I will
admit I haven't tried all functions. The reason is, all of this is a
heck of a lot easier with:
[perl products]
my $db = $Db{products};
my $phone = $Scratch->{item_code};
my $rowdata = $db->row_hash($phone);
my @cols = $db->columns();
&etc, &etc;
[/perl]
--
Red Hat, Inc., 3005 Nichols Rd., Hamilton, OH 45013
phone +1.513.523.7621 <mheins@redhat.com>
Fast, reliable, cheap. Pick two and we'll talk. -- unknown