Leser: 3
4 Einträge, 1 Seite |
SELECT vorname, nachname FROM users WHERE user_id = ?
1 2 3 4 5 6 7 8 9
package Froschpopo::Model::Database; use base qw/DBIx::Class::Schema/; __PACKAGE__->load_classes(qw/ User /); 1;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
package Froschpopo::Model::Database::User; use strict; use warnings; use base qw(DBIx::Class); __PACKAGE__->load_components( qw(PK::Auto Core) ); __PACKAGE__->table( 'user' ); __PACKAGE__->add_columns( qw( user_id vorname nachname )); __PACKAGE__->set_primary_key( 'user_id' ); 1;
1 2 3 4 5 6 7 8 9 10 11 12
#!/usr/bin/perl use strict; use warnings; use Froschpopo::Model::Database; my $schema = Froschpopo::Model::Database->connect($alles_wie_bei_dbi); my ($user) = $schema->resultset( 'User' )->search({ user_id => $user_id, }); print $user->vorname," ", $user->nachname;
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
#!/usr/bin/perl use strict; use warnings; use SQL::Abstract; use CGI; my $cgi = new CGI; my $sql = SQL::Abstract->new; my @tables = ('users'); my %where = ('users.geschlecht' => 'w'); if ($cgi->param('nur_user_mit_bild')) { push @tables, 'fotos'; $where{'fotos.user_id'} = \'= users.id'; } my ($sth, @bind) = $sql->select(\@tables, 'users.id', \%where); print $sth,"\n"; #SELECT users.id FROM users WHERE ( users.geschlecht = ? )
1 2 3 4 5 6 7 8 9 10
package Froschpopo::Model::Database; use base qw/DBIx::Class::Schema/; __PACKAGE__->load_classes(qw/ User Fotos /); 1;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
package Froschpopo::Model::Database::User; use strict; use warnings; use base qw(DBIx::Class); __PACKAGE__->load_components( qw(PK::Auto Core) ); __PACKAGE__->table( 'user' ); __PACKAGE__->add_columns( qw( user_id vorname nachname )); __PACKAGE__->set_primary_key( 'user_id' ); __PACKAGE__->has_many( Fotos => 'Froschpopo::Model:Database::Foto', { 'foreign.user_id' => 'self.user_id' } ); 1;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
package Froschpopo::Model::Database::Foto; use strict; use warnings; use base qw(DBIx::Class); __PACKAGE__->load_components( qw(PK::Auto Core) ); __PACKAGE__->table( 'fotos' ); __PACKAGE__->add_columns( qw( foto_id user_id path )); __PACKAGE__->set_primary_key( 'foto_id' ); __PACKAGE__->has_many( User => 'Froschpopo::Model:Database::User', { 'foreign.user_id' => 'self.user_id' } ); 1;
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
#!/usr/bin/perl use strict; use warnings; use CGI; use Froschpopo::Model::Database; my $cgi = CGI->new; my $schema = Froschpopo::Model::Database->connect($alles_wie_bei_dbi); my ($user) = $schema->resultset( 'User' )->search({ user_id => $user_id, }); if( $user ){ print $user->vorname," ", $user->nachname; if ($cgi->param('nur_user_mit_bild')) { my @fotos = $user->Fotos; for my $foto ( @fotos ){ print "Foto: ", $foto->path,"\n"; } } } else{ print "Kein User gefunden"; }
4 Einträge, 1 Seite |