오늘 날짜를 기준으로 SQL 문을 실행하려고합니다. 예를 들어 "오늘이 25 일이면 SQL을 실행하고 그렇지 않으면 오늘은 유효한 일과입니다"특정 달의 특정 날짜에만 SQL 실행
내가 연결하고 일부 HTML을 구축하기 전에 몇 가지 SQL을 실행하는 데DBI
을 사용하고 기본적으로
은 자동으로 이메일로 전송하는
을하지만, 나는 다음과 같은 구문 오류를 받고 있어요 :.
구문 오류에서 XXXXX, 근처에 ", 다른 사람은" (폭주 멀티 라인 { } 문자열 XX에서 시작) 줄 끝의 XXXXX에서 오른쪽 중괄호 또는 대괄호가 누락되었습니다.
나는 당신이 표현 (나는 내가하고 있을지도 모른다) 안에 직접적으로 임베드 할 수 없다는 것을 읽었다. 스크립트는 day 요소와 else
문 없이는 정상적으로 작동했습니다.
# Get the current day of the month (along with other date parts we can ignore)
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
## Filter based on day of week
my $sql;
if ($mday == 25) {
$sql = qq{<MY SQL STATEMENT HERE>
}
else {
say "Today is not a valid rundate";
}
## Prepare and execute the SQL
my $sth = $dbh->prepare($sql) or die "Failed to prepare SQL: " . $dbh->errstr;
$sth->execute() or die "Failed to execute SQL: " . $dbh->errstr;
## Start building the HTML output
my $html = qq{
<table style="width:100%"><thead>
<tr>
<th>#</th>
<th>col1</th>
<th>col2</th>
<th>col3</th>
</tr>
</thead>
};
## Loop round each row in the result set, and add to the HTML output for each one.
my $count = 0;
while (my $row = $sth->fetchrow_hashref) {
#
# process rows
$count++;
#say Dumper $row;
#say "$row->{col1}, $row->{col2}, $row->{col3}";
$html .= qq|
<tr>
<td align="right">$count.</td>
<td>$row->{col1}</td>
<td>$row->{col2}<td>
<td>$row->{col3}</td>
</tr>
|;
}
## Close the HTML
$html .= "</table>";
say "$count rows processed.";
$html .= "<h2>Report SQL</h2>The report was produced with the following SQL<p><pre>$sql</pre>";
## Send the mail
my $sender = new Mail::Sender();
$sender->Open({
from => 'email1',
to => $maildest,
subject => $mailsubj,
ctype => "text/html",
encoding => "quoted-printable",
smtp => "localhost"
}) or die $Mail::Sender::Error, "\n";
$sender->SendEnc($html);
$sender->Close();
$dbh->disconnect;
[mcve]가 아닙니다. 이것은 단지 번역 오류 일 수 있지만'$ sql = qq { '문에서'qq'를 닫지는 않았습니다. –
ThisSuitIsBlackNot