Jump to content

Hi...sorry for posting here, there's nobody in oop now...this is about class ?


jd2007

Recommended Posts

when i write a class which has functions to fetch data from a database and add data to a database, i use the construct to add table name and columns name ? see below for example....

 

<?php

class dbque
{
protected $l;
protected $u;
protected $p;
protected $db;
protected $con;
protected $d;
protected $table;
protected $idc;
protected $namec;
protected $emailc;
protected $name;
protected $email;

function __construct($l, $u, $p, $db, $table, $idc, $namec, $emailc)
{
  $this->l=$l;
  $this->u=$u;
  $this->p=$p;
  $this->db=$db;
  $this->table=$table;
  $this->idc=$idc;
  $this->namec=$namec;
  $this->emailc=$emailc;
}
  
  function connectdb()
  {
   $this->con=mysql_connect($this->l, $this->u, $this->p);
   $this->d=mysql_select_db($this->db, $this->con);
  }

  function addData($name, $email)
  {
   $this->name=$name;
   $this->email=$email;
   $this->que="insert into $this->table ($this->namec, $this->emailc) values ('$this->name', '$this->email')";
   $this->res=mysql_query($this->que);
  }
}

?>

 

all table and cols name are given values in a construct...and name and email data is given values using addData's function arguments....is this good practice ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.