use strict;
use warnings;

# use DBI;
# my $database = "books.db";
# my $database = ":memory:";
# メモリ上のデータベースへ接続
# my $dbh = DBI->connect("dbi:SQLite:dbname=$database");

use DBI;
my $database = "d1";
my $hostname = "localhost";
my $port = "mysql";
my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
my $user = "kono";
# my $password = "wtrhr3jk";
my $password = "";
my $dbh = DBI->connect($dsn, $user, $password);


# select文の実行
my $sth = $dbh->prepare("select count from counter where author = 'taro';");
$sth->execute;

my $count = 0;
# 各行のフェッチ
while (my @row = $sth->fetchrow_array) {
    # 各行を出力
    print join(', ', @row), "\n";
    $count = $row[0];
}

sleep 3;
$count ++;

$dbh->do("update counter set count = $count where author = 'taro'");

# データベースの切断
$dbh->disconnect;


