| Class-PObject documentation | view source | Contained in the Class-PObject distribution. |
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. 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.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.
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.
For author and copyright information refer to Class::PObject's online manual.
| Class-PObject documentation | view source | Contained in the Class-PObject distribution. |