mirror of
https://github.com/idanoo/nzart-exam-generator
synced 2025-07-02 22:32:17 +00:00
Initial Commit
This commit is contained in:
commit
391177596e
41 changed files with 1233 additions and 0 deletions
96
includes/classes/class.db.php
Executable file
96
includes/classes/class.db.php
Executable file
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
class db {
|
||||
private $host = DB_HOSTNAME;
|
||||
private $user = DB_USERNAME;
|
||||
private $pass = DB_PASSWORD;
|
||||
private $dbname = DB_DATABASE;
|
||||
|
||||
private $stmt;
|
||||
private $dbh;
|
||||
|
||||
public function __construct(){
|
||||
$dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname;
|
||||
$options = array(
|
||||
PDO::ATTR_PERSISTENT => true,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
|
||||
try {
|
||||
$this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
|
||||
} catch (PDOException $e) {
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function query($query){
|
||||
$this->stmt = $this->dbh->prepare($query);
|
||||
}
|
||||
|
||||
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(){
|
||||
return $this->stmt->execute();
|
||||
}
|
||||
|
||||
public function resultSet(){
|
||||
$this->execute();
|
||||
return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
public function single(){
|
||||
$this->execute();
|
||||
return $this->stmt->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
public function getObject() {
|
||||
$this->execute();
|
||||
return $this->stmt->fetchObject();
|
||||
}
|
||||
|
||||
public function rowCount(){
|
||||
return $this->stmt->rowCount();
|
||||
}
|
||||
|
||||
public function lastInsertId(){
|
||||
return $this->dbh->lastInsertId();
|
||||
}
|
||||
|
||||
public function beginTransaction(){
|
||||
return $this->dbh->beginTransaction();
|
||||
}
|
||||
|
||||
public function endTransaction(){
|
||||
return $this->dbh->commit();
|
||||
}
|
||||
|
||||
public function cancelTransaction(){
|
||||
return $this->dbh->rollBack();
|
||||
}
|
||||
|
||||
public function debugDumpParams(){
|
||||
return $this->stmt->debugDumpParams();
|
||||
}
|
||||
|
||||
public function kill(){
|
||||
$this->dbh = null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue