mvc-base/Classes/Model.php

79 lines
1.6 KiB
PHP
Executable File

<?php
abstract class Model{
protected $dbh;
protected $stmt;
public function __construct(){
$this->dbh = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME, DB_USER, DB_PASS);
}
public function query($query){
$this->stmt = $this->dbh->prepare($query);
}
//Binds the prep statement
public function bind($param, $value, $type = null){
if (is_null($type)) {
switch (true) {
case is_int($value):
$type = PDO::PARAM_INT;
break;
case is_bool($value):
$type = PDO::PARAM_BOOL;
break;
case is_null($value):
$type = PDO::PARAM_NULL;
break;
default:
$type = PDO::PARAM_STR;
}
}
$this->stmt->bindValue($param, $value, $type);
}
public function execute(){
$this->stmt->execute();
}
public function resultSet(){
$this->execute();
return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
}
public function lastInsertId(){
return $this->dbh->lastInsertId();
}
public function single(){
$this->execute();
return $this->stmt->fetch(PDO::FETCH_ASSOC);
}
public function getwichtel($wichtel){
$_SESSION['wichtelcode']=$wichtel;
switch($wichtel){
case md5('Klaas'):
$return='Klaas';
break;
case md5('Heike'):
$return='Heike';
break;
case md5('Harald'):
$return='Harald';
break;
case md5('Kathrin'):
$return='Kathrin';
break;
case md5('Steffen'):
$return='Steffen';
break;
case md5('Gunnar'):
$return='Gunnar';
break;
default:
$return='None';
break;
}
return $return;
}
}