App-Mowyw

 view release on metacpan or  search on metacpan

lib/App/Mowyw/Datasource/DBI.pm  view on Meta::CPAN

    $self->_connect;
    $self->{sth} = $self->{dbh}->prepare($opts->{sql});
    return $self;
}

sub _connect {
    my ($self) = @_;
    $self->{dbh} = DBI->connect(
        $self->{OPTIONS}{dsn},
        $self->{OPTIONS}{username},
        $self->{OPTIONS}{password},
        { RaiseError => 1, AutoCommit => 1, },
    );
}

sub _fetchrow {
    my $self = shift;
    my $sth = $self->{sth};
    my $row = $sth->fetchrow_hashref;
    if ($row){
        my $encoding = $self->{OPTIONS}{encoding} || 'utf8';

script/mowyw  view on Meta::CPAN

only contain distinct tags. Nested tags might work, but aren't officially
supported.

DBI is perls generic database interface. You can use it to access a database.
This has some limitations, for example you can't reuse database connections,
so every C<bind> statement actually opens a database connection on its own.

For the brave, here is an example of how to use it:

    [% bind my_db type:dbi dsn:DBI:mysql:database=yourdatabse;host=dbhost
       username:your_db_user password:you_db_password encoding:latin1
       sql:'SELECT headline, status FROM news LIMIT 10'
    %]
    [% for i in my_db %]
        <h2>Breaking news: [% readvar i.headline escape:html %]</h2>
        <p>Status: [% readvar i.status escape:html %]</p>
    [% endfor %]

The options are as follows:

=over

script/mowyw  view on Meta::CPAN

like C<mysql> or C<Pg> (for Postgres) and the driver options.

=item

The C<encoding> option is optional and defaults to C<utf-8>. You can use 
any character encoding here that Perl's cool C<Encode> module supports,
which is quite a many.

=item

the C<password> and C<username> options can be omitted if your database
doesn't ask for them

=back

This plugin may seem weird if you don't know Perl and its database module. If
that's the case, consider toying around with Perl and DBI first (it's really
worth a try).


=head1 CONFIGURATION FILE



( run in 1.169 second using v1.01-cache-2.11-cpan-49f99fa48dc )