Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Your site has saved me hours of work that I cannot begin to express my satisfaction..."

Geography

Where in the world do Tek-Tips members come from?

Newbie: My database cgi works but gives me weird output

shalomgod (Programmer)
13 Oct 06 19:12
#!/usr/bin/perl -w


use CGI;
use strict;
use DBI;


my $hello ="hello";

my $query = new CGI->new();



print $query->header("text/html"),


    $query->start_html(-title => "Database Test"),


 $query->p("Database Test"),


my  $db_handle = DBI->connect("dbi:mysql:database=Test;host=localhost;user=root;")
    or die;
   
my $sql = "SELECT * FROM users WHERE id = 2";
my $statement = $db_handle->prepare($sql)
    or die;

$statement->execute()
    or die;
    
while (my $row_ref = $statement->fetchrow_hashref())
{
    
    my $holder = $row_ref->{email};
    
    
    print $holder;
    
}



$db_handle->disconnect();



    $query->end_html;

Basically I get the correct output which is an email address. But i also get an unwanted hashcode..

DBI::db=HASH(0x8382f78)blabla@bla.co.uk

I get no compile errors  or anything so im wondering why DBI is getting printed out...

Maybe it has something to do with the fetch_row method?

Any help is much appreciated.
mbrooks (Programmer)
19 Oct 06 13:17
Because you are treating the hashref->{} like an array() which is incorrect.  Do it this way.

CODE

$statement->execute() or die;
    
my $row_ref = $statement->fetchrow_hashref()

print $row_ref->{email};

M. Brooks
http://mbrooks.info

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close