Class::PObject::Driver::mysql - MySQL Pobject Driver
use Class::PObject; pobject Person => { columns => ['id', 'name', 'email'], driver => 'mysql', datasource => { DSN => 'dbi:mysql:db_name', User => 'sherzodr', Password => 'marley01' } };
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 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.
DSN
User - username to connect to the database.
User
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.
Password
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 (_).
Table
_
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.
Handle
$dbh
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.
dbh()
save() - stores/updates the object
save()
_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.
_prepare_insert()
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.
If the table is detected to be missing in the database, it will attempt to create proper table for you. To have more control over how it creates this table, you can fill-in column types using tmap argument.
Class::PObject, Class::PObject::Driver::csv, Class::PObject::Driver::file
For author and copyright information refer to Class::PObject's online manual.
To install Class::PObject, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::PObject
CPAN shell
perl -MCPAN -e shell install Class::PObject
For more information on module installation, please visit the detailed CPAN module installation guide.