Skip to content

Instantly share code, notes, and snippets.

@yko
Created October 6, 2011 13:33
Show Gist options
  • Save yko/1267398 to your computer and use it in GitHub Desktop.
Save yko/1267398 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use DBI;
use Test::More tests => 3;
use strict;
use warnings;
my $options = {mysql_auto_reconnect => 1};
my $dbh = DBI->connect("dbi:mysql:", undef, undef, $options);
BAIL_OUT("MySQL connection failed: " . $DBI::errstr) unless $dbh;
my ($id) = $dbh->selectrow_array("SELECT CONNECTION_ID()");
like $id, qr/^\d+$/, "right connection id";
ok $dbh->do('KILL ?', undef, $id), "kill MySQL connection";
my ($value) = $dbh->selectrow_array("SELECT 42;");
is $value, 42, "reconnected";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment