Помощь в создании Hash масивов

Обсуждение серверного программирования.

Модераторы: Duncon, Yurich

Ответить
adakur
Сообщения: 1
Зарегистрирован: 27 сен 2005, 11:23

27 сен 2005, 11:50

Помогите пожалуйста! Нужна помощь!
Есть дапустим прописанный код:
%DEL=('01'=>{'server'=>'SUPER',
'host'=>'GOOD'});

А как нужно написать код чтобы он из базы MySQL сохранял для каждого $id --> $name и $data автоматически
...
my%DEL;
my $sth=$dbh->prepare(qq/SELECT `id`,`name`,`data` FROM `$SQL{tab}->{info};/);
$sth->execute;
while(my($id,$name,$data)=($sth->fetchrow_array))
{
@DEL{$id}=$name;# ??????????????? :?:
}
$sth->finish;
...
Заранее Спасибо! :?:
vlg
Сообщения: 5
Зарегистрирован: 26 сен 2004, 06:09

04 окт 2005, 21:28

while(my($id,$name,$data)=($sth->fetchrow_array))
{
$DEL{$id}={};
$DEL{$id}->{'name'} = $name;
$DEL{$id}->{'data'} = $data;
}
UUU
Сообщения: 309
Зарегистрирован: 17 фев 2004, 09:27
Откуда: Иваново
Контактная информация:

05 окт 2005, 10:00

Тут читая use MySQL нашел:

%hash = $sth->fetchhash;
return a complete hash. The keys in this hash are the column names of the table, the values are the table values. Be aware, that when you have a table with two identical column names, you will not be able to use this method without trashing one column. In such a case, you should use the fetchrow method.
Ответить