App::ZofCMS::Plugin::DBI is a App::ZofCMS plugin which provides means to retrieve and push data to/from SQL databases using DBI module.
Current functionality is limited. More will be added as the need arrises, let me know if you need something extra.
This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template
SYNOPSIS
In your main config file or ZofCMS template:
dbi = > {
dsn = > "DBI:mysql:database=test;host=localhost",
user = > 'test', # user,
pass = > 'test', # pass
opt = > { RaiseError = > 1, AutoCommit = > 0 },
},
In your ZofCMS template:
dbi = > {
dbi_get = > {
layout = > [ qw/name pass/ ],
sql = > [ 'SELECT * FROM test' ],
},
dbi_set = > sub {
my $query = shift;
if ( defined $query- >{user} and defined $query- >{pass} ) {
return [
[ 'DELETE FROM test WHERE name = ?;', undef, $query- >{user} ],
[ 'INSERT INTO test VALUES(?,?);', undef, @$query{qw/user pass/} ],
];
}
elsif ( defined $query- >{delete} and defined $query- >{user_to_delete} ) {
return [ 'DELETE FROM test WHERE name =?;', undef, $query- >{user_to_delete} ];
}
return;
},
},
In your HTML::Template template:
< form action="" method="POST" >
< div >
< label for="name" >Name: < /label >
< input id="name" type="text" name="user" value="< tmpl_var name="query_user" >" >< br >
< label for="pass" >Pass: < /label >
< input id="pass" type="text" name="pass" value="< tmpl_var name="query_pass" >" >< br >
< input type="submit" value="Add" >
< /div >
< /form >
< table >
< tmpl_loop name="dbi_var" >
< tr >
< td >< tmpl_var name="name" >< /td >
< td >< tmpl_var name="pass" >< /td >
< td >
< form action="" method="POST" >
< div >
< input type="hidden" name="user_to_delete" value="< tmpl_var name="name" >" >
< input type="submit" name="delete" value="Delete" >
< /div >
< /form >
< /td >
< /tr >
< /tmpl_loop >
< /table >
Product's homepage
Requirements:
· Perl