NAME

Apache2::Controller::SQL::MySQL - useful database methods for MySQL

SYNOPSIS

package MyApp::C::Foo;
use base qw( 
    Apache2::Controller 
    Apache2::Controller::MySQL
);
# ...

METHODS

insert_hash( \%hashref )

Insert data into the database.

# insert_hash()
# http://myapp.xyz/foo?ship=enterprise&captain=kirk&sci=spock&med=mccoy
sub register_crew {
    my ($self) = @_; 
    my $crew = $self->fields(qw( captain sci med ));
    $self->insert_hash({
        table   => 'crew',
        data    => $crew,
    });
    $self->print("Warp factor 5, engage.\n");
    return Apache2::Const::HTTP_OK;
}

Hashref argument supports these fields:

  • table

    The SQL table to insert into.

  • data

    The hash ref of field data to insert.

  • on_dup_sql

    Optional string of SQL for after 'ON DUPLICATE KEY UPDATE'. This MySQL SQL extension be used if this param is absent.

  • on_dup_bind

    Array ref of bind values for ?'s in on_dup_sql.