php mysqli create class

Solutions on MaxInterview for php mysqli create class by the best coders in the world

showing results for - "php mysqli create class"
Charlene
02 Jul 2018
1<?php
2/**
3* Simple Database class for PHP7+
4* The class contains main functions for your database. For a detailed documentation, see: https://webdeasy.com/
5* created 08.11.2017
6* 
7* @author LH
8*/
9class Database {
10  private $host, $database, $username, $password, $connection;
11  private $port = 3306;
12
13  /**  *
14
15Sets the connection credentials to connection to your database
16
17@param string $host - the host of your database
18@param string $username - the username of your database
19@param string $password - the password of your database
20@param string $database - your database name
21@param integer $port - the port of your database
22@param boolean $autoconnect - to auto connect to the database after settings connection credentials
23/function __construct($host, $username, $password, $database, $port = 3306, $autoconnect = true) { $this->host = $host; $this->database = $database; $this->username = $username; $this->password = $password; $this->port = $port; if($autoconnect) {   $this->open(); }}/**
24
25Open the connection to your database
26/function open() { $this->connection = new mysqli($this->host, $this->username, $this->password, $this->database, $this->port);}/**
27
28Close the connection to your database
29/function close() { $this->connection->close();}/**
30
31Execute your query
32
33@param string $query - your sql query
34@return the result of the executed query 
35/function query($query) { return $this->connection->query($query);}/**
36
37Escape your parameter
38
39@param string $string - your parameter to escape
40@return the escaped string
41/function escape($string) { return $this->connection->escape_string($query);}}?>