Initial commit
This commit is contained in:
74
lieder/star/DBController.php
Normal file
74
lieder/star/DBController.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
class DBController
|
||||
{
|
||||
|
||||
private $host = "localhost";
|
||||
|
||||
private $user = "root";
|
||||
|
||||
private $password = "";
|
||||
|
||||
private $database = "leitgedanken";
|
||||
|
||||
private static $conn;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->conn = mysqli_connect($this->host, $this->user, $this->password, $this->database);
|
||||
}
|
||||
|
||||
public static function getConnection()
|
||||
{
|
||||
if (empty($this->conn)) {
|
||||
new Database();
|
||||
}
|
||||
}
|
||||
|
||||
function getDBResult($query, $params = array())
|
||||
{
|
||||
$sql_statement = $this->conn->prepare($query);
|
||||
if (! empty($params)) {
|
||||
$this->bindParams($sql_statement, $params);
|
||||
}
|
||||
$sql_statement->execute();
|
||||
$result = $sql_statement->get_result();
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$resultset[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($resultset)) {
|
||||
return $resultset;
|
||||
}
|
||||
}
|
||||
|
||||
function updateDB($query, $params = array())
|
||||
{
|
||||
$sql_statement = $this->conn->prepare($query);
|
||||
if (! empty($params)) {
|
||||
$this->bindParams($sql_statement, $params);
|
||||
}
|
||||
$sql_statement->execute();
|
||||
}
|
||||
|
||||
function bindParams($sql_statement, $params)
|
||||
{
|
||||
$param_type = "";
|
||||
foreach ($params as $query_param) {
|
||||
$param_type .= $query_param["param_type"];
|
||||
}
|
||||
|
||||
$bind_params[] = & $param_type;
|
||||
foreach ($params as $k => $query_param) {
|
||||
$bind_params[] = & $params[$k]["param_value"];
|
||||
}
|
||||
|
||||
call_user_func_array(array(
|
||||
$sql_statement,
|
||||
'bind_param'
|
||||
), $bind_params);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user