Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Perl and DBI and CGI

by sapnac (Beadle)
on Jun 23, 2005 at 13:27 UTC ( [id://469386]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Perl and DBI and CGI
in thread Perl and DBI and CGI

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;

Replies are listed 'Best First'.
Re^4: Perl and DBI and CGI
by fmerges (Chaplain) on Jun 24, 2005 at 12:49 UTC
    Hi,

    The code is right, but using arrayref is more efficient/faster, consider it if you have a lot of data.

    Regards,
    ;-)
Re^4: Perl and DBI and CGI
by sOKOle (Acolyte) on Jun 23, 2005 at 14:05 UTC
    Sorry, it does not help.
      I am really sorry that it is not working for you. Actually, I created a temptable and tried executing the code that you are using;
      my $ref = $dbh->selectall_arrayref(" select name, email from testtable") || die $dbh->errstr; foreach my $person (@{$ref}) { my ($name,$emai) = @{$person}; print "<font color=\"red\" >Name : $name </font>"; print "<font color=\"blue\"> Email : $email </font><br>"; + }
      It runs just fine even with the "Dr. John Bull". Please check the database if some special characters are not slipped thru.
      here is the output
      Name : Dr. John Bull Email :
        Code Master,
        I couldn't believe what is happening that the same script gives different results on different machines, finally I add the following code to your script:
        my $ref = $dbh->selectall_arrayref(" select name, email from users") || die $dbh->errstr; foreach my $person (@{$ref}) { my ($name,$emai) = @{$person}; $_=$Name; s/ /_/g; $Name=$_; print "<font color=\"red\" >Name : $name </font>"; print "<font color=\"blue\"> Email : $email </font><br>"; }

        Surprisingly, the result is:
        Name : Dr._John_Bull Email :

        So, it is not DB error, but something else. Do you have any idea how to improve it?
        I can live with the "_" insted the " " but Perl beauty suffers.
        Best regards,
        sOKOle

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://469386]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-16 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found