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

hi all,

I have created a table with 7 columns in the database, and i need to display that in front end. When i tried to populate the value in the front end table using
sub service{ $self->{service} = Bugzilla->dbh->selectall_arrayref( 'SELECT servicenow, Task_Type, Short_Description, Customer, +Priority, Assignment_Group,Assignment_ID FROM service_now where bug_i +d=237177'); return $self->{service};}

Here service is a subroutine

Bugzilla is using standard DBI functions to interact with the database, through Bugzilla->dbh.

its displaying the reference and when i tried to dereference it, displays nothing or error as invalid token for $ symbol.

I am calling that inside the HTML file [% bug.service FILTER none %] -> this displays reference [% $bug.service FILTER none %] -> gives error as $ invalid token.

Can we use anyother method instead of selectall_arrayref(). Pls suggest me.Thanks in advance

Replies are listed 'Best First'.
Re: need help in accessing sql table
by kcott (Archbishop) on Nov 05, 2013 at 06:58 UTC

    G'day perlaspirant,

    Welcome to the monastery.

    Your post is missing various pieces of information that would help us help you. For instance, use of $self->{service} suggests either code within an instance method or broken encapsulation outside of one; and Bugzilla->dbh->... suggests a Bugzilla::dbh() class method — in both cases we're left to make guesses, which could easily be wrong, because you haven't shown the relevant code or context.

    From your description, it sounds like you're getting specific error messages; however, you only supply a prosaic narrative rather than the actual messages.

    Please read the guidelines in "How do I post a question effectively?" to see what information to post and how to present it. In addition, "How do I change/delete my post?" explains how to update your post.

    I also note you've written "Can we use anyother method instead of selectall_arrayref()." but the code you've posted is using another method, i.e. selectall_array(). A correction or clarification regarding this would be useful.

    -- Ken

Re: need help in accessing sql table
by marinersk (Priest) on Nov 05, 2013 at 18:37 UTC
    Can't get your code to run without the Bugzillamodule. While I'm sure it would be fun to learn all about how that module works and go through the effort to install it here, I really don't have the time. So --

    Just so you can see what is happening, I would suggest:

    • Not running the code from a web page, but from your system directly, and;
    • Changing the code to something like the following:
    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Bugzilla; { my $retval = Bugzilla->dbh->selectall_arrayref ( 'SELECT servicenow, Task_Type, Short_Description, Customer, Pr +iority, Assignment_Group,Assignment_ID FROM service_now where bug_id= +237177' ); print Dumper $retval; } exit; __END__ C:\Steve\Dev\PerlMonks\P-2013-11-05@1128-DBI>testdb.pl Can't locate Bugzilla.pm in @INC (@INC contains: C:\Steve\Perl C:/Perl/Perl-5.16.3.1603/site/lib C:/Perl/Perl-5.16.3.1603/lib . ) at C:\Steve\Dev\PerlMonks\P-2013-11-05@1128-DBI\testdb.pl line 7. BEGIN failed--compilation aborted at C:\Steve\Dev\PerlMonks\P-2013-11-05@1128-DBI\testdb.pl line 7.