NAME

Class::PObject::Driver::mysql - MySQL Pobject Driver

SYNOPSIS

use Class::PObject;
pobject Person => {
    columns => ['id', 'name', 'email'],
    driver  => 'mysql',
    datasource => {
        DSN => 'dbi:mysql:db_name',
        User => 'sherzodr',
        Password => 'marley01'
    }
};

DESCRIPTION

Class::PObject::Driver::mysql is a direct subclass of Class::PObjecet::Driver::DBI. It inherits all the base functionality needed for all the DBI-related classes. For details of these methods and their specifications refer to Class::PObject::Driver and Class::PObject::Driver::DBI.

DATASOURCE

datasource attribute should be in the form of a hashref. The following keys are supported

  • DSN - provides a DSN string suitable for the first argument of DBI->connect(...). Usually it should be dbi:mysql:$database_name.

  • User - username to connect to the database.

  • Password - password required by the User to connect to the database. If the user doesn't require any passwords, you can set it to undef.

  • Table - defines the name of the table that objects will be stored in. If this is missing will default to the name of the object, non-alphanumeric characters replaced with underscore (_).

  • Handle attribute is useful if you already have $dbh handy. If $dbh is used, DSN, User and Password attributes will be obsolete nor make sense.

METHODS

Class::PObject::Driver::mysql (re-)defines following methods of its own

  • dbh() base DBI method is overridden with the version that creates a DBI handle using DSN datasource attribute.

  • save() - stores/updates the object

  • _prepare_insert() redefines base method of the same name with the version that generates a REPLACE SQL statement instead of default INSERT SQL statement. This allows the driver to either leave "insert or update?" problem to MySQL.

    This implies that table's id column should be of AUTO_INCREMENT type. This will ensure that MySQL will take care of creating auto-incrementing unique object ids for you.

SEE ALSO

Class::PObject, Class::PObject::Driver::csv, Class::PObject::Driver::file

AUTHOR

Sherzod Ruzmetov <sherzodr@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2003 by Sherzod B. Ruzmetov.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.