4 Einträge, 1 Seite |
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
use strict;
use DBI;
use DBD::mysql;
require Exporter;
my @ISA = ('Exporter');
my @EXPORT_OK = qw(new user_get_users);
sub new {
my $dsn = 'DBI:mysql:moorland:localhost'; # datasourcename: wenn myserver weggelassen wird,
# wird standardmäßig localhost verwendet.
my $attributes = { PrintError => 0, RaiseError => 0, "AutoCommit" => 1, }; # siehe Doku zu DBI
$pgdb = DBI->connect($dsn, $user, $password, $attributes)
or main::writeDbhError("Error in connecting to $dsn", die => 1);
# immer Returncodes und Fehler auswerten!!!
} #new
sub get_res {
# Returns an sorted twodimentional Array: [ Foreach Ressourceid: [ ressourceid, ressourcename, quantity ] ]
my $self = shift;
my $userid = shift;
if (my $dataref = dbselect("SELECT restype, quantity FROM res_distribution WHERE userid=$userid")) {
foreach my $ressource (@$dataref) {
$ressource->{'RESNAME'} =
dbselect("SELECT name AS resname FROM res_types WHERE id=" . $ressource->{'RESTYPE'})->[0]->{'RESNAME'}
#or die("Fehler, Dem".$db->lasterror);
or die("Fehler: $pgdb->errstr\n");
}
return $dataref;
} else {
return;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/perl
# muss das Verzeichnis für die Module angeben
BEGIN{
push @INC, 'c:/apache/cgi-bin/moorland/public_html/cgi-bin/';
}
use warnings;
use strict;
use CGI;
use moorlanddb; # <-- das Modul
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use Data::Dumper;
my $db = new moorlanddb() or die("Couldn't connect to Database\n");
print Dumper( $db );
# Ausgabe:
# $VAR1 = bless( {}, 'DBI::db' );
my $userid = 1;
print $db->get_res($userid) or $db->lasterror; # <-- Zeile 67
4 Einträge, 1 Seite |