0
For some reason, my code is resulting in error
Notice: Undefined Index IRRAD
when trying to perform a query in the Oracle database. The PHP code I am 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 column names as in PHP code. The index Range works correctly, however, the index IRRAD it accuses the cited error.
Is there a rule to be followed to read the headers or is there something wrong with the code?
Tries to recover the name in low box,
$row['irrad']
– rray
continues with Undefined Index. Other queries in the same template are running smoothly. I’ve also never had problems with Mysql query. I’ll post the rest of the code to see if there’s any interference
– Rafael
that, might help.
– rray
When you do
print_r($row);
appears what? can put in the comments even the result.– rray
Array ( [RANGE] => 0 - 300 )
– Rafael
Remove the alias of
irrad
and run the print_r again, I hope something different will come.– rray
Continue only with index RANGE :/
– Rafael
I think I get it. For some reason I was returning NULL to the IRRAD column and when the query returns NULL, the
$row
does not receive the column.– Rafael
I do not know if the oracle has any particularity but I believe that the column should be defined with null and not simply exist.
– rray
I added a checker to evaluate whether null returns and is working correctly. Add an answer with the functional code or edit the question? Thank you very much!
– Rafael
If you solved the problem, create an answer :).
– rray