You're not checking the result of your query properly.
If the second parameter of explode is marked to be no string, it's surely no string.
Thus: your sql seems not to work in the context of your PHP script, although it is proper SQL.
Check your $conn
variable if it's a proper connection
dump sqlsrv error like:
$sth = sqlsrv_query($conn,"
SELECT routines.date, routines.time,
SUM( CASE WHEN measurements.title = 'T_Luft_Temperatur' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS Temperatur
FROM routines
INNER JOIN measure_routine ON routines.id = measure_routine.routine_id
INNER JOIN measurements ON measure_routine.measure_id = measurements.id
INNER JOIN pools ON measure_routine.pool_id = pools.id
GROUP BY routines.date, routines.time
ORDER BY routines.date, routines.time;
;");
if( $sth === false ) {
die( print_r( sqlsrv_errors(), true));
}
EDITED:
as from your last edit, the image (why an image?) shows the following error message:
explode() expects parameter 2 to be string, object given in ...
that means your variable $dateString = $r['date'];
is a DateTime object.
At the end you don't need to explode that, since you may access the members through the getters of this object:
$dateObj = $r['date'];
$year = $dateObj->format('Y');