<?php
/*account class
2022-02-09*/
require_once('class.databank.php');
require_once('class.account.php');
class accountDB extends databank{
public function __construct(){
parent::__construct();
$sql = "
CREATE TABLE IF NOT EXISTS `account` (
`id` Int(11) NOT NULL AUTO_INCREMENT,
`firstname` Varchar(255) NULL ,
`lastname` Varchar(255) NULL ,
`street` Varchar(255) NULL ,
`number` Varchar(255) NULL ,
`postal` Varchar(255) NULL ,
`description` Text NULL ,
`birthdate` Datetime NULL ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1 ;";
try {
$connection = $this->connect();
$connection->exec($sql);
return true;
}catch (PDOException $e) {
return false;
}
}
public function insertAsObject($object){
$connection = $this->connect();
$stmt = $connection->prepare("insert into account values(null,:firstname,:lastname,:street,:number,:postal,:description,:birthdate);");
$stmt->bindParam(":firstname", $object->firstname);
$stmt->bindParam(":lastname", $object->lastname);
$stmt->bindParam(":street", $object->street);
$stmt->bindParam(":number", $object->number);
$stmt->bindParam(":postal", $object->postal);
$stmt->bindParam(":description", $object->description);
$stmt->bindParam(":birthdate", $object->birthdate);
return $stmt->execute();
}
public function getAll(){
$connection = $this->connect();
$sql = "SELECT * FROM account";
$connection = $connection->query($sql);
return $resultaat->fetchAll(PDO::FETCH_OBJ);
}
public function getByKey($key){
$connection = $this->connect();
$stmt = $connection->prepare("SELECT * FROM account WHERE id = :id");
$stmt->bindParam(":id", $key);
$stmt->execute();
return $stmt->fetchObject("account");
}
public function update($object){
$connection = $this->connect();
$sql= "update account set firstname = :firstname,lastname = :lastname,street = :street,number = :number,postal = :postal,description = :description,birthdate = :birthdate where id= :id";
$stmt = $connection->prepare($sql);
$stmt->bindParam(":id", $object->id);
$stmt->bindParam(":firstname", $object->firstname);
$stmt->bindParam(":lastname", $object->lastname);
$stmt->bindParam(":street", $object->street);
$stmt->bindParam(":number", $object->number);
$stmt->bindParam(":postal", $object->postal);
$stmt->bindParam(":description", $object->description);
$stmt->bindParam(":birthdate", $object->birthdate);
return $stmt->execute();
}
public function delete($id){
$connection = $this->connect();
$stmt = $connection->prepare("DELETE FROM account WHERE id = :id");
$stmt->bindParam(":id", $id);
$stmt->execute();
}
}
?>
|