Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Perl and DBI and CGI

by sOKOle (Acolyte)
on Jun 23, 2005 at 12:34 UTC ( #469370=perlquestion: print w/replies, xml ) Need Help??

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

My best friends, please help me to improve this:
The Part of CGI Code is:
$query = "SELECT * FROM users"; $sth = $dbh->prepare($query); $sth->execute(); $sth->bind_columns(undef, \$Name, \$Email); while($sth->fetch()){ print "$Name, $Email";} $sth->finish(); $dbh->disconnect;erl
The Problem and Question are:
When the Name in my Data Base is "Dr. John Bull" only "Dr." is printed. How to improve the code to have full name printed?
Thank you in advance,
Sincerely yours,

Replies are listed 'Best First'.
Re: Perl and DBI and CGI
by monkey_boy (Priest) on Jun 23, 2005 at 13:00 UTC
    I agree with blazar on both points, but try this & see if it sheds some light:
    use Data::Dumper; my $ref = $dbh->selectall_arrayref("select * from users") || die $dbh->errstr; print Dumper($ref);

    This is not a Signature...
      Dear monkey_boy ! Thank you, Much better, but I have no idea how to improve formating and assign fields to the variables: $Name and $Email. In other words, how to make
      print "<font color=\"red\"> $Name"; print "<font color=\"ble\"> $Email";
      Regards, sOKOle
        You would be better specifying the column names in the sql, thus would be able to help you more, also dont forget to close your font tags , something like this:
        my $ref = $dbh->selectall_arrayref(" select name , email , age from users ") || die $dbh->errstr; foreach my $person (@{$ref}) { my ($name,$email,$age) = @{$person}; print "<font color=\"red\" > $name </font>"; print "<font color=\"blue\"> $email </font>"; };

        This is not a Signature...
        Hi! Check if this is helps...
        $query = "SELECT Name, Email FROM users"; $sth = $dbh->prepare($query); $sth->execute(); while($Name,$Email) = $sth->fetchrow_array){ print "$Name, $Email";} $sth->finish(); $dbh->disconnect;
        Hint: use alternate delimiters, e.g. qq|"$whatever"|.
Re: Perl and DBI and CGI
by blazar (Canon) on Jun 23, 2005 at 12:53 UTC
    At the risk of being downvoted, two mostly OT and probably irrelevant for you, cmts:
    1. This seems to be more of a DB question than an actual Perl one; i.e. I don't think things are different when you directly access the DB as opposed to interface with it with perl.
    2. You have quite a strange indenting style, and an IMHO confusing one. Maybe giving a peek into perlstyle would help.
    As far as the first point goes, I have only extremely limited experience with this stuff myself, but there may be preferable approaches to interfacing with DBses. Here at work they're all enthusiastic with Class::DBI.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://469370]
Approved by Mutant
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2022-01-18 18:42 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (54 votes). Check out past polls.