I have actually seen similar questions on this "Fatal error: Uncaught exception 'PDOException'". But I have not been able to use have I have seen to resolve the challenge am having.
Below the code and the error message
<?php
$sql5 = " set @rownum := 0;
set @sum := 0;
select DISTINCT(ROUND(the_avg,4))
FROM (
select water_level,
@rownum := (@rownum + 1) as rownum,
@sum := IF(@rownum mod 7 = 1,0 + water_level,@sum + water_level) as running_sum,
IF(@rownum mod 7 = 0,@sum / 7,NULL) as the_avg
FROM " .$table." WHERE record_month_year = '".$startDateReport."'
order by id ASC
) s ";
$result5 = $db->prepare($sql5);
$result5->execute();
while ($rowReport = $result5->fetch(PDO::FETCH_ASSOC)) {
?>
<tr style="font-size:11px;">
<td><?php echo $rowReport['the_avg'] ; ?></td>
</tr>
<?php
}
?>
The line 83 is :
while ($rowReport = $result5->fetch(PDO::FETCH_ASSOC)) {
error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error' in C:\xampp\htdocs\awos\includes\loadboreholedatareport.php:83 Stack trace: #0 C:\xampp\htdocs\awos\includes\loadboreholedatareport.php(83): PDOStatement->fetch() #1 C:\xampp\htdocs\awos\borData-report.php(46): include('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\awos\includes\loadboreholedatareport.php on line 83.
You can only do one query at a time with PDO.. Do them separately, like this..
$db->query("set @rownum := 0");
$db->query("set @sum := 0");
$sql5 = "select DISTINCT(ROUND(the_avg,4))
FROM (
select water_level,
@rownum := (@rownum + 1) as rownum,
@sum := IF(@rownum mod 7 = 1,0 + water_level,@sum + water_level) as running_sum,
IF(@rownum mod 7 = 0,@sum / 7,NULL) as the_avg
FROM " .$table." WHERE record_month_year = '".$startDateReport."'
order by id ASC
) s ";
And the rest would be the same.