Use local script to login to remote web site (modify Header) Simple script to feed your site with some RSS that you like ;)
Mar 30

I’m going to talk about some good object oriented practices for small/medium projects. The object oriented programming itself will save you enourmous amount of time. The inheritance is part of the Object Oriented Programming (OOP) and is very good thing that is going to save you even more time when you start to use some object oriented model in your programming.

Let’s say we need to have some root class - lets say “Base”, with the __construct() (the class’s constructor) - notice that since PHP 5.0 the constructor of a class is defined in __constructs(), instead of “the-name-of-your-class”(). Anyway you can define the constructor information in Base() as well, but better do it in __construct, because you don’t know if there will be support for the old PHP 4 constructors in PHP 6 :)

so let’s get on business..

In our Base class we are going to add some protected variables (they are going to be viewed from all delivered classes, and from the Base itself)
In our case we add a constructor that creates a mysqli connection to our host, and that’s all we are going to use this class for - for the connection with the DataBase.

Class Base {
protected $host = “localhost”;
protected $user = “root”;
protected $pass = “”;
protected $name = “MerchantsDB;
protected $char = “utf-8″;
protected $table = “merchants”;

function __construct(){
if(($this->link = new mysqli($this->host, $this->user, $this->pass, $this->name)) === false){ $this->error(”cant login”);

}else{
//echo “logged
“;
$this->link->set_charset($this->char) or $this->error(”set charset”);

}
}
}

Class Merchant extends Base {

function AddMerchant($mName, $mURL, $mAgent, $mUID, $mDate, $mManager, $mStatus, $mComment){

$q = mysqli_query($this->link, “INSERT INTO “.$this->table.” (`MerchantName`, `MerchantURL`, `MerchantAgent`, `MerchantUserID`, `MerchantReceivedDate`, `MerchantManager`, `MerchantStatus`, `MerchantComment`) VALUES (’$mName’, ‘$mURL’, ‘$mAgent’, ‘$mUID’, ‘$mDate’, ‘$mManager’, ‘$mStatus’, ‘$mComment’)”);

if($q){
echo “Merchant Successfully added !!”;
return true;
}else{
echo “Invalid input data or duplicated URL !!”;
return false;
}

}

function RemoveByID($id){
if(mysqli_query($this->link,”Delete from “.$this->table.” where MerchantID = “.$id)){
//echo “entry $id successfully removed”;
}
}
}

function GetAll($order){
$q = mysqli_query($this->link,”select * from “.$this->table.” ORDER BY “.$order.” desc”);
$count = 1;

while($row = mysqli_fetch_assoc($q)){
include(”Merchants.table.inc.php”);

$count++;
}
}

}

So we have a class Merchant that is delivered from Base and so we inherit $link variable from the Base’s constructor. So when we call $this->link we have a fully working mysqli connection (that is more secure than the standard mysql).

As you see we have created 3 very simple functions of the Merchant class GetAll, RemoveByID, and AddMerchant
in all of them we use $this->link delivered from our base class, which is very cool, because we can have a bunch of other classes - like Product, Car, Student… whatever and we don’t have to specify a single connection for each of them - we just inherit it from the Base class - with “extends Base” at the class declaration :)

that’s it for now i hope this example was useful for you :)

Leave a Reply

Spam Protection by WP-SpamFree

  • generic name viagra
  • viagra trial pack
  • european online pharmacy
  • new stop smoking medication
  • health vitamins
  • online discount pharmacy
  • pet ear infection remedies
  • pain management drugs
  • nerve pain remedy
  • organic vitamins
  • antibiotic overdose
  • how to lower high blood pressure
  • bone muscle pain
  • cancer medicine
  • effexor dosages
  • latest treatment for heart attack
  • buy brand names drugs
  • allegra drug
  • heart chest pain
  • bactrim online
  • tretinoin retin a
  • discount medication
  • clonazepam treatment
  • genaric viagra
  • taking diflucan
  • what can help heart failure
  • no prescription pain
  • how to relieve back pain
  • levitra side affects
  • dog health advice
  • leukemia medications
  • congestive heart failure online
  • help reduce high blood pressure
  • levitra warfarin
  • free ultram
  • treating aids in africa
  • how can i stop smoking
  • on-line drugs
  • benadryl dosage
  • prevention of hypertension
  • buy cialis online viagra
  • cialis herbal
  • flu shot
  • buy cialis tadalafil
  • what is elavil
  • weight loss information
  • male enhancements
  • aspirin therapy
  • strengthen immune system
  • viagra women
  • dog antibiotics
  • us online pharmacies
  • nolvadex generic
  • benicar generic
  • do diet pills work
  • parasite killer human
  • treatment of chlamydia
  • what valium does
  • weight loss stuff for free
  • cialis cheapest
  • natural health for dogs
  • arthritis pain medicine
  • gout cures
  • high blood pressure prevention
  • cla buy
  • pet ear infection remedies
  • generic 5mg proscar cheap
  • cheap impotence drug generic cialis delivery
  • weight loss pill that works
  • allergy medication
  • new weight loss drug
  • natural antibiotic anti-biotic
  • diabetes prevention
  • rheumatoid arthritis medications
  • medication gonorrhea
  • alzheimers meds
  • cialis benefits
  • medications ativan
  • drug hydroxyzine
  • meds without prescriptions
  • mens health supplements
  • baby acne
  • birth control online
  • pet supplies products
  • do diet pills work
  • cheap viagra soft
  • nexium use
  • cialis versus viagra
  • female health problems
  • abnormal blood clots
  • buy cialis without a prescription
  • breast augmentation info
  • new drugs for depression
  • arthritis pain medicine
  • cholesterol canada
  • what is hoodia
  • osteoporosis help
  • abscess infection cats
  • health products for men
  • treatment for high blood pressure
  • levitra generic
  • treatment of breast cancer
  • mobic tablets
  • strattera pharmacy
  • drug sarafem
  • carisoprodol dosage
  • women's health tips
  • viagra from usa
  • chest pain
  • allergy medicine
  • blood clots lungs
  • buy drugs online
  • teeth whitening methods
  • buying prescription drugs online
  • how to lower blood sugar
  • parkinson's drugs
  • lexapro info
  • asthma asthma
  • cialis 50mg
  • new levitra
  • severe hair loss
  • pain medication safe while pregnant
  • male health vitamins
  • otc sleep aids
  • vitamin b-12
  • high blood pressure treatment
  • carisoprodol medication
  • living with heart failure
  • diabetes cure
  • women body building
  • cat's health
  • buspirone dosage
  • diet for high blood pressure
  • generic viagra lowest price
  • bupropion 150 mg
  • information on gout
  • what does clomid do
  • medication price
  • weight loss tablet
  • top weight loss drugs
  • discount skin care
  • amitriptyline uses
  • where to buy cialis
  • online cheap soma
  • order alli
  • stomach pain
  • xanax price
  • buy canadian drugs
  • bronchitis medications
  • weight loss tablet
  • pet safety products
  • preventing bone loss
  • advice care health pet uk
  • discount pharmacies in canada
  • natural sleep aid
  • super flu
  • prostate cancer treatment
  • treating dependent edema
  • herbs for impotence
  • wrinkle reducers
  • cheapest cialis generic
  • cheapest cialis uk
  • dog health care
  • cialis 5
  • smoking cessation programs
  • generic online ultram
  • adhd in children
  • valium high
  • pet safety products
  • medicines for insomnia
  • human parasite
  • simvastatin tablets
  • free diabetes products
  • online prescription pharmacy
  • pet med
  • purchase vitamins
  • penis enlargement result
  • medication skelaxin
  • buy body building supplement
  • burning fat
  • left side pain
  • depression drugs
  • pain drugs
  • tramadol and dosage
  • discount weight loss prescription
  • weight loss exercise tips
  • drugs online
  • teeth white
  • stop smoke
  • sildenafil online
  • professional viagra
  • blockers calcium channel
  • avapro 150mg
  • fda levitra
  • blue pills
  • pain medicine online ordering
  • male health drugs
  • chronic congestive heart failure
  • normal blood pressure
  • stronger erections