• PERL DBI 自动重连问题


    [root@wx03 mojo]# cat relink.pl 
    use Mojolicious::Lite;
    use JSON qw/encode_json decode_json/;
    use Encode;
    no strict;
    no warnings;
    use JSON;
    use POSIX;
    use JSON::RPC::Client;
    use Data::Dumper;
    use DBI;
    # /foo?user=sri`
    my %hash=();
    my $dbUser='DEVOPS';
    my $user="root";
    my $passwd="R00t,uHagt.xx";
    my $dbh  = DBI->connect("dbi:mysql:database=$dbUser;host=127.0.0.1;port=3306",$user,$passwd) or die "can't connect to database ". DBI-errstr;
    get '/api/relink' => sub{
      my $c = shift;
      my @arr2=();
       my $env = $c->param('env');
      my $hostSql = qq{select ip,info,env from publish_info where env='$env';};
    my ($a1, $a2, $a3,$a4,$a5,$a6,$a7,$a8,$a9);
    
    my $selStmt = $dbh->prepare($hostSql);
    $selStmt->execute();
    $selStmt->bind_columns(undef, $a1, $a2,$a3);
    while( $selStmt->fetch() ){
    print "$a1 is $a1
    ";
    print "$a2 is $a2
    ";
    print "$a3 is $a3
    ";
    push (@arr2, "$a1  $a2  $a3" );
      };
    
      $c->render(json =>  @arr2);
    };
    app->start;
    
    [root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    ["1.1.1.1  aa  test"]
    
    停止数据库,启动数据库
    [][root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]
    [root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]# curl http://127.0.0.1:3000/api/relink?env=test
    [][root@wx03 ~]# 
    
    代码报错:
    Server available at http://127.0.0.1:3000
    $a1 is 1.1.1.1
    $a2 is aa
    $a3 is test
    $a1 is 1.1.1.1
    $a2 is aa
    $a3 is test
    DBD::mysql::st execute failed: Lost connection to MySQL server during query at /root/mojo/relink.pl line 25.
    DBD::mysql::st bind_columns failed: Statement has no result columns to bind (perhaps you need to successfully call execute first, or again) at /root/mojo/relink.pl line 26.
    DBD::mysql::st fetch failed: fetch() without execute() at /root/mojo/relink.pl line 27.
    
    DBD::mysql::st execute failed: MySQL server has gone away at /root/mojo/relink.pl line 25.
    DBD::mysql::st bind_columns failed: Statement has no result columns to bind (perhaps you need to successfully call execute first, or again) at /root/mojo/relink.pl line 26.
    DBD::mysql::st fetch failed: fetch() without execute() at /root/mojo/relink.pl line 27.
    
    
    没有自动重连
    
    

  • 相关阅读:
    大道至简第六章-从编程到工程
    Java动手动脑-接口继承
    随机数生成数组元素求和
    大道至简第五章-失败的过程也是过程
    课堂-字符串加密
    字符串加密
    课堂动手动脑-3及字符串加密
    java课堂回答
    读后感
    从编辑懂工程
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350197.html
Copyright © 2020-2023  润新知