use strict;
use warnings;
# DB Account Parameters
my $driver = "mysql";
my $database = "emegadb";
my $user = "*****";
my $password = "*******";
my $dsn = "DBI:mysql:$database;mysql_local_infile=ON";
use DBI;
my $dbh = DBI->connect($dsn,$user,$password)
|| die "Unable to connect to database. $DBI::errstr.\n";
my $sth = $dbh->prepare("select * from today1")
|| die "cannot prepare select. $DBI::errstr.\n";
$sth->execute || die "cannot execute select. $DBI::errstr.\n";
while(my $row = $sth->fetchrow_hashref){
my $daily = join (',', values %$row);
#print "$daily \n";
push @table1, "$daily";
}
$sth->finish;
$dbh->disconnect();
MAIL:
use Mail::Sendmail qw(sendmail %mailcfg);
#print "Content-type:text/html\n\n";
%mail = (
To => 'me@mail.com',
From => 'daily_adjust@mail.net',
Subject => " DAILY ADJUST - DATABASE CAPTURE",
Message => "DB @table1\n");
$mailcfg{smtp} = [qw(db-ibmv1.mail.net)];
sendmail(%mail) or die $Mail::Sendmail::error;
END:
exit(0);
这提供了以下结果:
DB 95,1,15476,1016,289.7,288.8,000000,03:00:00,2015-08-29
286.9,15194,1016,287.7,000000,06:00:00,2015-08-29,100,2
3,95,09:00:00,2015-08-29,000000,15476,289.7,1016,289.0
17379,1016,294.8,294.0,000000,12:00:00,2015-08-29,76,4
77,5,294.5,295.2,17569,1.... ETC
我想要的是 - 列名
+------+------------+----------+----------+------+-------+-------+--------+--------+
| id | date | time | percent | hpa | min | max | dem | sumadd |
+------+------------+----------+----------+------+-------+-------+--------+--------+
| 1 | 2015-08-29 | 03:00:00 | 95 | 1016 | 288.8 | 289.7 | 15476 | 000000 |
| 2 | 2015-08-29 | 06:00:00 | 100 | 1016 | 286.9 | 287.7 | 15194 | 000000 |
| 3 | 2015-08-29 | 09:00:00 | 95 | 1016 | 289.0 | 289.7 | 15476 | 000000 |