Oh sorry. Dummer Anfängerfehler von mir.
Bin aus dem lexikalischen geltungsbereicht rausgeflogen.
Hier jetzt getesteter Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
format_c@elvis ~
$ mysql -Dtest -utestuser -ppassword
Welcome to the MySQL monitor. Commands end with; or \g.
Your MySQL connection id is 6 to server version: 3.23.49-max-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> select * from config;
+-------------+--------------+
| config_name | config_value |
+-------------+--------------+
| schlüssel1 | wert1 |
| schlüssel2 | wert2 |
| schlüssel3 | wert3 |
| schlüssel4 | wert4 |
+-------------+--------------+
4 rows in set (0.00 sec)
mysql> \q
Bye
format_c@elvis ~
$ perl
use strict;
use DBI;
use Data::Dumper;
my %config = ();
my $dbh = DBI->connect('DBI:mysql:database=test','testuser','password')
or die DBI::errstr();
my $sth = $dbh->prepare('SELECT * FROM config') or die $dbh->errstr();
$sth->execute() or die $dbh->errstr();
while (my ($key,$value) = $sth->fetchrow_array()) {
$config{$key} = $value;
}
print Dumper(\%config);
_ _ END _ _
$VAR1 = {
'schlüssel3' => 'wert3',
'schlüssel1' => 'wert1',
'schlüssel2' => 'wert2',
'schlüssel4' => 'wert4'
};
format_c@elvis ~
$