Mojo::MySQL5::Database - Database
use Mojo::MySQL5::Database; my $db = Mojo::MySQL5::Database->new( mysql => $mysql, connection => Mojo::MySQL5::Connection->new);
Mojo::MySQL5::Database is a container for Mojo::MySQL5::Connection handles used by Mojo::MySQL5.
Mojo::MySQL5::Database implements the following attributes.
my $c = $db->connection; $db = $db->connection(Mojo::MySQL5::Connection->new);
Database connection used for all queries.
Mojo::MySQL5 object this database belongs to.
Mojo::MySQL5::Database inherits all methods from Mojo::EventEmitter and implements the following ones.
my $num = $db->backlog;
Number of waiting non-blocking queries.
my $tx = $db->begin;
Begin transaction and return Mojo::MySQL5::Transaction object, which will automatically roll back the transaction unless "commit" in Mojo::MySQL5::Transaction bas been called before it is destroyed.
# Insert rows in a transaction eval { my $tx = $db->begin; $db->query('insert into frameworks values (?)', 'Catalyst'); $db->query('insert into frameworks values (?)', 'Mojolicious'); $tx->commit; }; say $@ if $@;
$db->connect;
Connect to MySQL server.
$db->disconnect;
Disconnect database connection and prevent it from getting cached again.
my $pid = $db->pid;
Return the connection id of the backend server process.
my $bool = $db->ping;
Check database connection.
my $results = $db->query('select * from foo'); my $results = $db->query('insert into foo values (?, ?, ?)', @values);
Execute a blocking statement and return a Mojo::MySQL5::Results object with the results. You can also append a callback to perform operation non-blocking.
$db->query('select * from foo' => sub { my ($db, $err, $results) = @_; ... }); Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
my $escaped = $db->quote($str);
Quote string value for passing to SQL query.
my $escaped = $db->quote_id($id);
Quote identifier for passing to SQL query.
Mojo::MySQL5.
To install Mojo::MySQL5, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::MySQL5
CPAN shell
perl -MCPAN -e shell install Mojo::MySQL5
For more information on module installation, please visit the detailed CPAN module installation guide.