AnyEvent-MySQL
view release on metacpan or search on metacpan
lib/AnyEvent/MySQL.pm view on Meta::CPAN
package AnyEvent::MySQL;
use 5.006;
use strict;
use warnings;
=encoding utf8
=head1 NAME
AnyEvent::MySQL - Pure Perl AnyEvent socket implementation of MySQL client
=head1 VERSION
Version 1.2.1
=cut
lib/AnyEvent/MySQL.pm view on Meta::CPAN
use lib 'lib';
use AnyEvent::MySQL;
my $end = AE::cv;
my $dbh = AnyEvent::MySQL->connect("DBI:mysql:database=test;host=127.0.0.1;port=3306", "ptest", "pass", { PrintError => 1 }, sub {
my($dbh) = @_;
if( $dbh ) {
warn "Connect success!";
$dbh->pre_do("set names latin1");
$dbh->pre_do("set names utf8");
}
else {
warn "Connect fail: $AnyEvent::MySQL::errstr ($AnyEvent::MySQL::err)";
$end->send;
}
});
$dbh->do("select * from t1 where a<=?", {}, 15, sub {
my $rv = shift;
if( defined($rv) ) {
lib/AnyEvent/MySQL.pm view on Meta::CPAN
}
=head2 $dbh = AnyEvent::MySQL::db->new($dsn, $username, [$auth, [\%attr,]] [$cb->($dbh, $next_guard)])
$cb will be called when each time the db connection is connected, reconnected,
or tried but failed.
If failed, the $dbh in the $cb's args will be undef.
You can do some connection initialization here, such as
set names utf8;
But you should NOT rely on this for work flow control,
cause the reconnection can occur anytime.
=cut
sub new {
my $cb = ref($_[-1]) eq 'CODE' ? pop : \&AnyEvent::MySQL::_empty_cb;
my($class, $dsn, $username, $auth, $attr) = @_;
my $dbh = bless { _ => [] }, $class;
( run in 1.108 second using v1.01-cache-2.11-cpan-49f99fa48dc )