PHP Classes

File: output/class.accountDB.php

Recommend this page to a friend!
  Classes of Martijn Waeyenbergh   PHP MySQL Generator   output/class.accountDB.php   Download  
File: output/class.accountDB.php
Role: Sample output
Content type: text/plain
Description: Example Account Database CLASS
Class: PHP MySQL Generator
Generate classes to access MySQL database tables
Author: By
Last change:
Date: 2 years ago
Size: 2,848 bytes
 

Contents

Class file image Download
<?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(); } } ?>