The Perl Toolchain Summit 2025 Needs You: You can help 🙏 Learn more

NAME

MojoX::Mysql::DB - Connect DB

SYNOPSIS

use Mojo::Util qw(dumper);
my %config = (
user=>'root',
password=>undef,
server=>[
{dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', type=>'master'},
{dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', type=>'slave'},
{dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', id=>1, type=>'master'},
{dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', id=>1, type=>'slave'},
{dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', id=>2, type=>'master'},
{dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', id=>2, type=>'slave'},
]
);
my $mysql = MojoX::Mysql->new(%config);
my $dbh = $mysql->db->connect_master;

ATTRIBUTES

id

$mysql->id(1); # choice id server

METHODS

connect_master

$mysql->db->connect_master;

Return connect object.

connect_slave

$mysql->db->connect_slave;

Return connect object.

commit

$mysql->db->commit;

Commit on all servers

rollback

$mysql->db->rollback;

Rollback on all servers

disconnect

$mysql->db->disconnect;

Disconnect on all servers