jd2007 Posted September 18, 2007 Share Posted September 18, 2007 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/69751-hisorry-for-posting-here-theres-nobody-in-oop-nowthis-is-about-class/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.