Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DBController
- {
- private $host = “localhost”;
- private $user = “root”;
- private $password = “”;
- private $database = “shopping_cart”;
- 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);
- }
- }
Add Comment
Please, Sign In to add comment