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 ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.