class Customer {
protected $db;
//public $data = [];
public function __construct(PDO $db){
$this->db = $db;
}
public function create(array $data){
$query = "INSERT INTO `customers` VALUE (?, ?, ?, ?)";
$stmt = $this->db->prepare($query);
//$data check
return $stmt->execute($data);
}
public function update(array $data){
//return bool
}
public function delete(int $id){
//return bool
}
public function get($query, array $params = []){
$stmt = $this->db->prepare($query);
$stmt->execute($params);
//$this->data = $stmt->fetchAll();
return $stmt->fetchAll();
}
}
class CollectionCustomer {
protected $obj;
public function __construct(Customer $obj){
$this->obj = $obj;
}
public function getAll(){
$query = "SELECT * FROM `customers`";
return $this->obj->get($query);
}
public function getById(int $id){
$query = "SELECT * FROM `customers` WHERE `id` = :id";
return $this->obj->get($query, [':id' => $id]);
}
public function getByName($str){
$query = "SELECT * FROM `customers` WHERE `name` LIKE :name";
return $this->obj->get($query, [':name' => '%'.$str.'%']);
}
//и тд.
}
$db = new PDO();
$customer = new Customer($db);
$collection = new CollectionCustomer($customer);
//var_dump($collection->getAll());
var_dump($collection->getById(1));
function site(){
echo site_header();
//...
}
function site_header(){
echo logo();
echo menu();
echo phones();
//и тд.
}
function logo(){
return '123-45-67';
}
$url = 'http://site.ru/';
$page_content = file_get_contents($url);
preg_match('/<title>(.*)<\/title>/', $page_content, $result);
echo $result[1];
exit;