db=$p_cn; $this->bd_id=$id; $this->po_id=null;$this->bc_id=null;$this->pcm_val=null; $this->bh_id=null; } /*!\brief insert into the database and set the this->bd_id of the * inserted row * \return the bd_id */ function add () { $array=array($this->po_id, $this->bc_id, $this->pcm_val, $this->bh_id); $sql="insert into bud_detail (po_id,bc_id,pcm_val,bh_id) ". " values ($1,$2,$3,$4) returning bd_id "; $a=ExecSqlParam($this->db,$sql,$array); $this->bd_id=pg_fetch_result($a,0,0); } /*!\brief update thanks the bd_id if bd_id == 0 returns directly * */ function update() { if ( $this->bd_id == 0) return; $sql="update bud_detail set po_id=$1,". "bc_id=$2,". "pcm_val=$3 ". " where bd_id=$4"; $array=array($this->po_id, $this->bc_id, $this->pcm_val, $this->bd_id ); ExecSqlParam($this->db,$sql,$array); } /*!\brief delete in bud_detail */ function delete() { ExecSql($this->db,"delete from bud_detail where bd_id=".$this->bd_id); } /*!\brief load one row from the table Bud_Detail and makes an object of it */ function load() { if ( $this->bd_id == 0 ) return ; $sql="select * ". " from bud_detail ". " where ". " bd_id =".$this->bd_id; $res=ExecSql($this->db,$sql); if ( pg_NumRows($res) == 0 ) return; $a=pg_fetch_array($res,0); foreach ( array('bc_id','po_id','pcm_val') as $key) { $this->{"$key"}=$a[$key]; } } /*!\brief convert an array into in data member * * */ function get_from_array($p_array) { foreach (array('bd_id','po_id','bc_id','pcm_val','bh_id') as $attr) if ( isset ( $p_array[$attr] )) $this->$attr=$p_array[$attr]; } /*!\brief test the object for developper * */ static function test_me() { $cn=DbConnect(dossier::id()); $a=new Bud_Detail($cn); $a->po_id=4; $a->bh_id=4; echo "