For some reason, my code is resulting in error
Notice: Undefined Index IRRAD
when attempting to query the Oracle database. The PHP code I'm using:
set_time_limit( 600 );
date_default_timezone_set('America/Sao_Paulo');
$query2 = 'SELECT \'0 - 300\' as intervalo, ROUND(SUM('.$irradInc.')/3600000, 2) as irrad FROM '.$tabela.' WHERE '.$irradInc.' BETWEEN 0 AND 300 AND TS_SAMPLETM BETWEEN TO_DATE(\''.$data1.'\', \'DD/MM/YY\') AND TO_DATE(\''.($data2->format('d/m/y')).'\', \'DD/MM/YY\')
UNION ALL
SELECT \'300 - 700\', ROUND(SUM('.$irradInc.')/3600000, 2) FROM '.$tabela.' WHERE '.$irradInc.' BETWEEN 300 AND 700 AND TS_SAMPLETM BETWEEN TO_DATE(\''.$data1.'\', \'DD/MM/YY\') AND TO_DATE(\''.($data2->format('d/m/y')).'\', \'DD/MM/YY\')
UNION ALL
SELECT \'700 - 1000\', ROUND(SUM('.$irradInc.')/3600000, 2) FROM '.$tabela.' WHERE '.$irradInc.' BETWEEN 700 AND 1000 AND TS_SAMPLETM BETWEEN TO_DATE(\''.$data1.'\', \'DD/MM/YY\') AND TO_DATE(\''.($data2->format('d/m/y')).'\', \'DD/MM/YY\')
UNION ALL
SELECT \'1000 - 1200\', ROUND(SUM('.$irradInc.')/3600000, 2) FROM '.$tabela.' WHERE '.$irradInc.' BETWEEN 1000 AND 1200 AND TS_SAMPLETM BETWEEN TO_DATE(\''.$data1.'\', \'DD/MM/YY\') AND TO_DATE(\''.($data2->format('d/m/y')).'\', \'DD/MM/YY\')
UNION ALL
SELECT \'> 1200\', ROUND(SUM('.$irradInc.')/3600000, 2) FROM '.$tabela.' WHERE '.$irradInc.' > 1200 AND TS_SAMPLETM BETWEEN TO_DATE(\''.$data1.'\', \'DD/MM/YY\') AND TO_DATE(\''.($data2->format('d/m/y')).'\', \'DD/MM/YY\')';
//echo $query2;
$conn = oci_connect('****', '***', '****');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$stid = oci_parse($conn, $query2);
oci_execute($stid);
$array = array();
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_LOBS)) {
array_push(
$array,
array(
'value' => $row['irrad'],
'label' => $row['INTERVALO']
)
);
unset($row);
}
The query I'm running is:
SELECT \'0 - 300\' as intervalo, ROUND(SUM('.$irradInc.')/3600000, 2) as irrad FROM '.$tabela.' WHERE '.$irradInc.' BETWEEN 0 AND 300 AND TS_SAMPLETM BETWEEN TO_DATE(\''.$data1.'\', \'DD/MM/YY\') AND TO_DATE(\''.($data2->format('d/m/y')).'\', \'DD/MM/YY\')
Using the query directly in Oracle's SQL Developer, the result comes correctly, with the column names as it is in the code in PHP. The index Interval works correctly, however, the index IRRAD it accuses the error quoted.
Is there a rule to follow to read the headers, or is there something wrong with the code?