db=$p_cn; $this->ga_id=null; $this->ga_description=null; } /*! * \brief insert into the database an object */ function insert() { $sql=" insert into groupe_analytique values ('%s','%s')"; $sql=sprintf($sql,pg_escape_string($this->ga_id), pg_escape_string($this->ga_description)); try { ExecSql($this->db,$sql); } catch (Exception $a) { echo 'Doublon !!'; } } /*! * \brief remove from the database */ function remove() { $this->ga_id=str_replace(' ','',$this->ga_id); $this->ga_id=strtoupper($this->ga_id); $sql=" delete from groupe_analytique where ga_id='".pg_escape_string($this->ga_id)."'"; ExecSql($this->db,$sql); } /*! * \brief load from the database and make an object */ function load() { $sql="select ga_id, ga_description from groupe_analytique where". " ga_id = ".$this->ga_id; $res=ExecSql($this->db,$sql); $array=pg_fetch_all($res); if ( ! empty($array) ) { $this->ga_id=$array['ga_id']; $this->ga_description=$array['ga_description']; } } /*! * \brief fill the object thanks an array * \param array */ function get_from_array($p_array) { $this->ga_id=$p_array['ga_id']; $this->ga_description=$p_array['ga_description']; } function myList() { $sql=" select ga_id,ga_description from groupe_analytique"; $r=ExecSql($this->db,$sql); $array=pg_fetch_all($r); $res=array(); if ( ! empty($array)) { foreach ($array as $m ) { $obj= new Anc_Group($this->db); $obj->get_from_array($m); $res[]=clone $obj; } } return $res; } static function test_me() { $cn=DbConnect(dossier::id()); print_r($cn); $o=new Anc_Group($cn); $r=$o->myList(); print_r($r); echo '
'; print_r($o); $o->ga_id="DD' dd dDD"; $o->ga_description="Test 1"; $o->remove(); // $o->insert(); $o->ga_id="DD"; $o->ga_description="Test 1"; $o->remove(); $r=$o->myList(); print_r($r); } }