쿼리 결과에 문제가 있습니다. getSales()
함수는 처음 호출 할 때 훌륭하게 작동합니다. 다시 호출 될 때 쿼리는 결과를 생성하지 않습니다.PDO - 쿼리 결과가 반환되지 않습니다.
abstract class Reporting {
protected function connect() {
try {
$this->dbh = PDOConnection::getInstance();
if (!$this->dbh instanceof PDO) {
throw new CustomException('Unable to connect to database');
}
}
catch (CustomException $e) {
echo $e;
}
}
}
class TenMinuteSales extends Reporting {
protected $date;
public function __construct($date) {
$this->date = new DateTime($date);
$this->date = $this->date->format('Y-m-d');
}
public function beginReport() {
parent::connect();
}
public function getSales($meridiem, $date) {
try {
$statement = "SELECT directory.location, IFNULL(sales.daily_sales,0.00) AS sales, IFNULL(sales.cover_counts,0) AS covers
FROM t_directory directory
LEFT JOIN v_sales_all sales
ON sales.site_id = directory.site_id
AND sales.business_date = :date
AND sales.meridiem = :meridiem
ORDER BY directory.site_id ASC
LIMIT :totalLocations";
$sth = $this->dbh->prepare($statement);
$sth->bindParam(':date', $date, PDO::PARAM_STR);
$sth->bindParam(':meridiem', $meridiem, PDO::PARAM_STR);
$sth->bindParam(':totalLocations', $this->totalLocations, PDO::PARAM_INT);
$sth->execute();
switch ($meridiem) {
case 'AM':
$this->amSales = $sth->fetchAll(PDO::FETCH_ASSOC);
return $this->amSales;
case 'PM':
$this->pmSales = $sth->fetchAll(PDO::FETCH_ASSOC);
return $this->pmSales;
}
}
catch (CustomException $e) {
echo $e;
}
}
$tms = new TenMinuteSales($date);
$tms->beginReport();
$amSales = $tms->getSales('AM', $date);
$pmSales = $tms->getSales('PM', $date);
내가 AM 또는 PM 판매 번호를 getSales()
를 호출, 함수가 성공적으로 데이터를 반환 : 여기에 코드의 작은 덩어리이다. 두 번째 호출 할 때 함수는 데이터를 반환하지 않습니다. 그 라인을 따라 결과 나 무언가를 자유롭게해야하는지 잘 모르겠습니다. unset($sth)
과 $sth->closeCursor()
을 시도했지만 어느 것도 내 문제를 해결하지 못했습니다. 내 문제를 해결하는 데 큰 도움이 될 것입니다. 자세한 내용이 필요한 경우 알려 주시기 바랍니다. 이 같이
'$ this-> totalLocations'은 정의되지 않았으며 아마도 NULL이 맞습니까? – Wrikken
나는 그것이 설정된 코드를 포함하지 않았습니다. 이 질문의 목적을 위해. '$ this-> totalLocations' = 20 – Brett
문제와 관련이 없지만 try/catch를 악용하는 것 같습니다. getSales()에서의 catch는 결코 일어나지 않을 것입니다. 왜냐하면 아무 것도 그 레벨에 던지지 않기 때문입니다. – Kenaniah