update,
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
class DatabaseAccess{
|
||||
|
||||
private $conn;
|
||||
|
||||
public function __construct(){
|
||||
$this->conn = new DatabaseConnection();
|
||||
$this->conn = $this->conn->getConnection();
|
||||
}
|
||||
|
||||
public function query($query, $paramType = null, $params = array()){
|
||||
if (mysqli_connect_errno()) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
$stmt = $this->conn->prepare($query);
|
||||
|
||||
if($paramType != null){
|
||||
$stmt->bind_param($paramType, ...$params);
|
||||
}
|
||||
|
||||
$runStmt = $stmt->execute();
|
||||
if (!$runStmt) {
|
||||
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
|
||||
}else{
|
||||
$method = explode(' ', $query)[0];
|
||||
$result;
|
||||
switch (strtoupper($method)) {
|
||||
case "SELECT":
|
||||
$result = $stmt->get_result();
|
||||
//var_dump($result);
|
||||
//$row = $result->fetch_array(MYSQLI_ASSOC);
|
||||
//var_dump($row);
|
||||
//echo "$row[lastName]";
|
||||
break;
|
||||
case 'UPDATE':
|
||||
case "INSERT":
|
||||
case 'DELETE':
|
||||
$result = $stmt->affected_rows;
|
||||
break;
|
||||
}
|
||||
$stmt->close();
|
||||
//$this->conn->close();
|
||||
return $result;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function getInsertId(){
|
||||
return mysqli_insert_id($this->conn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
class DatabaseConnection {
|
||||
|
||||
private $hostname;
|
||||
private $database;
|
||||
private $username;
|
||||
private $password;
|
||||
|
||||
public function __construct(){
|
||||
$this->hostname = "127.0.0.1";
|
||||
$this->database = "ProjectDB";
|
||||
$this->username = "root";
|
||||
$this->password = "";
|
||||
}
|
||||
|
||||
public function getConnection(){
|
||||
$conn = mysqli_connect($this->hostname, $this->username, $this->password, $this->database);
|
||||
return $conn;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
class Route {
|
||||
|
||||
public static $routes = array();
|
||||
|
||||
public static function map($route, $function){
|
||||
self::$routes[] = $route;
|
||||
//print_r(self::$routes);
|
||||
|
||||
if($_GET['url'] == $route){
|
||||
$function->__invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
class View {
|
||||
|
||||
public static function render($viewName, $data){
|
||||
require_once("./static/$viewName.php");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user