Skip to content
Permalink
e7bebbb684
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
41 lines (34 sloc) 1.25 KB
<?php
require_once 'database.php';
class Person {
protected $id;
protected $firstname;
protected $lastname;
protected $email;
protected $phone;
public function __construct($id=0) {
if ($id !== 0) {
$db = getDatabase();
$query = $db->prepare( "SELECT * from people WHERE id = :id " ); // return all fields (*) from the table WHERE the id is the var $id passed to the function
$query->bindParam( ':id', $id );
$query->execute(); // Run the SQL query on our database
$query->setFetchMode( PDO::FETCH_OBJ ); // A PHP method to tell the database we want to return all the data as objects with each table represented as a property of that object. This will be the case for most of our calls that return information from the database. http://php.net/manual/en/pdo.constants.php
$data = $query->fetchAll();
$data = $data[0];
// Build our local object
$this->id = $data->id;
$this->firstname = $data->firstname;
$this->lastname = $data->lastname;
$this->phone = $data->phone;
$this->email = $data->email;
}
}
public function get () {
$res['id'] = $this->id;
$res['firstname'] = $this->firstname;
$res['lastnamename'] = $this->lastname;
$res['email'] = $this->email;
$res['phone'] = $this->phone;
return $res;
}
}