I am fairly new to OOP and PHP. I worked my way through Kevin Yank's book and wanted to keep advancing to some OOP concepts. But I am a bit lost and I need help.

I followed Kevin's instructions and created a db.inc.php file for my PDO db connection:


//db connection using PDO class object

try {

    //create new PDO class object
    $pdo = new PDO('mysql:host=;port=3307;dbname=mydbname','dbuser','password');
    $pdo->exec('SET NAMES "utf8"');
catch (PDOException $e)
    //if unable to connect, tell us why
    $output = 'Unable to connect to the database server 2.'.$e->getMessage();
    include 'output.html.php';

I created a the following class:


class Vendor {
    protected $name;
    protected $address;
    protected $city;
    protected $state;
    protected $postal;
    protected $country;
    protected $tel;
    protected $email;
    protected $web;
    public function __construct(){
        //typically first function to appear in a class
        // Constructor using MagicMethod
        $this->name = $name;
        $this->address = $address;
        $this->city = $city;
        $this->state = $state;
        $this->postal = $postal;
        $this->country = $country;
        $this->tel= $tel;
        $this->email = $email;
        $this->web = $web;
    public  function getVendors($pdo){
        //get all vendor data from db
            //prepares a statement for execution and returns a statement object
            $query = $pdo->prepare("SELECT * FROM vendor ORDER BY name");
            $vendors = array();
            foreach ($query->fetchAll() as $row){
                //create array of member objects
                $vendors[] = new Vendor($row);
            return array($vendors);
        catch (PDOException $e)
            //handle any errors
            $output = 'Error fetching vendors: ' . $e->getMessage();
            include 'output.html.php';

        }//end try catch
    }//end function
    public function setName( $name ){
        $this->name = $value;
    public function setAddress( $address ){
        $this->address = $value;
   public function setCity( $city ){
        $this->city = $value;
   public function setState( $state ){
        $this->state = $value;
    public function setPostal( $postal ){
        $this->postal = $value;
    public function setCountry( $country ){
        $this->country = $value;
    public function setTel( $tel ){
        $this->tel = $value;
    public function setEmail( $email ){
        $this->email = $value;
    public function setWeb( $web ){
        $this->web = $value;
    public function getName(){
        return $this->name;
   public function getAddress(){
        return $this->address;
    public function getCity(){
        return $this->city;
    public function getState(){
        return $this->state;
    public function getPostal(){
        return $this->postal;
    public function getCountry(){
        return $this->country;
    public function getTel(){
        return $this->tel;
    public function getEmail(){
        return $this->email;
    public function getWeb(){
        return $this->web;
I have an index.php file that is calling the list of vendors


//get all vendors

include_once $_SERVER['DOCUMENT_ROOT'] .'/db.inc.php'; 
include_once $_SERVER['DOCUMENT_ROOT'] .'/includes/Vendor.Class.php'; 

//instantiate class
$vendor = new Vendor();

//calling my function to get a list of vendors
$vendors = $vendor->getVendors($pdo);

//trying to receive an array of objects but basically getting empty objects
echo $vendors;

//output to template
include 'output.html.php';
The idea is to then use a template/output html file to output data:

<?php foreach ($vendors as $vendor){
            $name = $vendor->getName();
            $address2 = $vendor->getAddress2();
            $city = $vendor->getCity();
            $zip = $vendor->getZip();
            $web = $vendor->getWeb();
            $phone = $vendor->getTel();

My questions:

1. In my vendor class I am creating an array of Vendor Objects - is this the correct OOP way of returning my rows from DB?
2. If my country and city are IDs, and each has their own class, when and where is the appropriate time to call those classes and use getCity($id) and getCountry($id) to get name values instead of ids?
3. Also, if am have to loop through the result set, and that does involve getting the city and country name values, is it ok to do that in the html output file? or should that be done in my index.php file (controller)?

Any assistance is greatly appreciated.