<?php
	
	//--------------------------------------------------------------------------------------------------------
	include ("../_identifiants/sql_identification_sans_base.php");
	$mysql_base = 'AQCM05_SITE_' . $p_aqcm_SITE_ID ;
	
	$link = mysqli_connect($mysql_host,$mysql_user,$mysql_password, $mysql_base);
	if (!$link) {
		$code_erreur = 100;
		echo "Connexion impossible à la base de donnée MySQL !" . PHP_EOL; echo '</br>'; flush() ;
		echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo '</br>'; flush() ;
		echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; echo '</br>'; flush() ;
		exit($code_erreur);
	}

	//----------------------------------------------------------
	$query_get_parameters = [] ;

	$query_get_parameters[0] = "SELECT aqcm_CO2_TRIG_0,aqcm_CO2_TRIG_1,aqcm_CO2_TRIG_2,aqcm_CO2_TRIG_3,aqcm_CO2_TRIG_4,aqcm_CO2_TRIG_5 FROM AQCM05_TRIG_CO2 WHERE (idx=1)";

	$query_get_parameters[1] = "SELECT aqcm_COV_TRIG_0,aqcm_COV_TRIG_1,aqcm_COV_TRIG_2,aqcm_COV_TRIG_3,aqcm_COV_TRIG_4,aqcm_COV_TRIG_5 FROM AQCM05_TRIG_COV WHERE (idx=1)";

	$query_get_parameters[2] = "SELECT aqcm_HCHO_TRIG_0,aqcm_HCHO_TRIG_1,aqcm_HCHO_TRIG_2,aqcm_HCHO_TRIG_3,aqcm_HCHO_TRIG_4,aqcm_HCHO_TRIG_5 FROM AQCM05_TRIG_HCHO WHERE (idx=1)";

	$query_get_parameters[3] = "SELECT aqcm_HR_TRIG_0,aqcm_HR_TRIG_1,aqcm_HR_TRIG_2,aqcm_HR_TRIG_3,aqcm_HR_TRIG_4,aqcm_HR_TRIG_5 FROM AQCM05_TRIG_HR WHERE (idx=1)";

	$query_get_parameters[4] = "SELECT aqcm_NOX_TRIG_0,aqcm_NOX_TRIG_1,aqcm_NOX_TRIG_2,aqcm_NOX_TRIG_3,aqcm_NOX_TRIG_4,aqcm_NOX_TRIG_5 FROM AQCM05_TRIG_NOX WHERE (idx=1)";

	$query_get_parameters[5] = "SELECT aqcm_PM25_TRIG_0,aqcm_PM25_TRIG_1,aqcm_PM25_TRIG_2,aqcm_PM25_TRIG_3,aqcm_PM25_TRIG_4,aqcm_PM25_TRIG_5 FROM AQCM05_TRIG_PM25 WHERE (idx=1)";

	$query_get_parameters[6] = "SELECT aqcm_SPL_TRIG_0,aqcm_SPL_TRIG_1,aqcm_SPL_TRIG_2,aqcm_SPL_TRIG_3,aqcm_SPL_TRIG_4,aqcm_SPL_TRIG_5 FROM AQCM05_TRIG_SPL WHERE (idx=1)";

	$query_get_parameters[7] = "SELECT aqcm_T_TRIG_0,aqcm_T_TRIG_1,aqcm_T_TRIG_2,aqcm_T_TRIG_3,aqcm_T_TRIG_4,aqcm_T_TRIG_5 FROM AQCM05_TRIG_T WHERE (idx=1)";
	
	$query_get_parameters[8] = "SELECT aqcm_LUX_TRIG_0,aqcm_LUX_TRIG_1,aqcm_LUX_TRIG_2,aqcm_LUX_TRIG_3,aqcm_LUX_TRIG_4,aqcm_LUX_TRIG_5 FROM AQCM05_TRIG_LUX WHERE (idx=1)";
	
	//----------------------------------------------------------
	$code_erreur = 0;
	
	for ($i=0; $i < sizeof($query_get_parameters); $i++) {
		$result = mysqli_query($link, $query_get_parameters[$i]); 
		
		if (!$result) {	
			$code_erreur = 10*($i+1) + 1;
			echo "MySQL = " . $code_erreur . "<br>"; flush() ;
			echo "</br>";  flush() ;
			mysqli_close($link);
			exit($code_erreur);
		}
		else {
			if (mysqli_num_rows($result) == 0) {	
				$code_erreur = 10*($i+1) + 2;
				echo "MySQL = " . $code_erreur . "<br>"; flush() ;
				echo "</br>";  flush() ;
				mysqli_close($link);
				exit($code_erreur);
			}
			else {
				if ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) { 
					extract($row);
				}
				else {
					$code_erreur = 10*($i+1) + 3;
					echo "MySQL = " . $code_erreur . "<br>"; flush() ;
					echo "</br>";  flush() ;
					mysqli_close($link);
					exit($code_erreur);
				}
			}
		}
	}

	//----------------------------------------------------------
	
?>
