Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: My database cgi works but gives me weird output

Status
Not open for further replies.

shalomgod

Programmer
Jan 18, 2006
5
JP
#!/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.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top