I have my own module for doing this job, sorry I missed many
posts of this thread but here is what I do:

- The target is automatically : add , update, select data
  from a table reading data typed by the user.

- I didn't want to use the Apache api, so it even can be
  used out of apache, so I called it : Persistence::DBI
  thought I don't like this name much.

In This example I work with HTML::Mason, but as
I said before it can be used from whatever thingie, even
out of the web.

I'm using currently this in production sites and it saves
me a lot of work.


EXAMPLE OF CODE:
It's a little harder than this but you'll get the idea:

##customer.html#######################################3

<%init>
# Make the object
my $customer=Persistence::DBI->open(
        table => 'customers',
        field_id => 'idCustomer'
        field_data => \%ARGS
);

if (defined $_delete) {
        $customer->delete;
}

</%init>


## The html form is this way:

<form>
  <input type="text" name="name" value="<% $customer->name %>">
  <input type="text" name="phone" value="<% $customer->phone %>">
  <input type="submit" name="_save" value="save">
% if (defined $customer->idCustomer) {
        <input type="hidden" name="idCustomer" 
                value="<% $customer->idCustomer %>">
        <input type="submit" name="_delete" value="delete">
% }
</form>


It works this way:
- if you supply the value of the id field it does a select
- if you supply all the fields but the id, it does an insert
- if you supply id and fields it does an update

Before calling the object you can check the values supplied
by the user to verify the values are correct.

If you modify values of the object it updates the data.


I'll accept name changes and I'll send the module to 
whoever wants it. I checked it with MySQL and SQL server.
The module come with pods and it installs fine like any
other module.It needs the field_id be auto increment.

-- 
 - frankie -

Reply via email to