> On Wed, Feb 06, 2002 at 01:57:21PM +0000, Wiliam Stephens wrote:
>> Hi
>>
>> I want to retrieve a row of MySQL data using Perl and DBI, so I do it
>> like this:
>>
>> [code]
>> my $sqlquery = qq|SELECT * FROM ata_members WHERE id=$id|;
>> $sth = $dbh->prepare($sqlquery);
>> $sth->execute or die("Can't execute SQL query. [$DBI::err]
>> $DBI::errstr");
>> $ref = $sth->fetchrow_hashref();
>> $sth->finish;
>> [/code]
>
> Seems reasonable.
>
>> But what I want is to populate a %hash with all name/value pairs
>> retruned from this query.
>
> Are you sure that there is data returned?
>
>> I tried:
>>
>> [code]
>> my %hash = %$ref;
>> [/code]
>>
>> But that doesn't work.
>
> It should. I'm not sure why you'd want to do it, but it should work.
>
> Jeremy
Thanks, Jeremy.
It does work. The hash did indeed get populated but I failed to notice this.
Is there a way to pull a hash directly out of a SQL query result though?
Can I omit this step or not?
Thanks.
--
Wiliam Stephens
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php