<?php

class debut
{
	function get_debut($id_pat)
	{
		$q = "SELECT * FROM debut WHERE id_pat = '" . $id_pat . "'";
		$r = mysql_query($q);
	
		if ($r)
		{
			$n = mysql_fetch_assoc($r);
			return $n;
		}
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());
	
		return false;
	}
	
	function edit_debut($id_pat, $alc_debut, $alc_conso, $alc_usage, $alc_ivresse, $alc_abst, $alc_abst_duree, $tab_debut, $tab_usage)
	{
		if ($this->del_debut($id_pat))
		{
			$q = "INSERT INTO debut (id_pat, alc_debut, alc_conso, alc_usage, alc_ivresse, alc_abst, alc_abst_duree, tab_debut, tab_usage) VALUES ('" . $id_pat . "', '" . $alc_debut . "', '" . $alc_conso . "', '" . $alc_usage . "', '" . $alc_ivresse . "', '" . $alc_abst . "', '" . $alc_abst_duree . "', '" . $tab_debut . "', '" . $tab_usage . "')";
			$r = mysql_query($q);
		
			if ($r) 
				return true;
			else
				die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());
		}
		
		return false;
	}

	function del_debut($id_pat)
	{
		$q = "DELETE FROM debut WHERE id_pat = '" . $id_pat . "'";
		$r = mysql_query($q);

		if ($r) 
		{
			$q = "OPTIMIZE TABLE debut";
			$r = mysql_query($q);

			return true;
		}
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());
	
		return false;
	}
}

?>