I have created this MySQLI Class. I wanted to know if this class is secure enough to be used on the production websites or more improvements can be done to this class.
<?php
// Make local variables of the mySQL variables from the Configuration file
$db_host = DB_HOST;
$db_user = DB_USER;
$db_pass = DB_PASSWORD;
$db_name = DB_NAME;
class database{
protected $link, $results, $num_rows;
public function __construct($db_host, $db_user, $db_pass, $db_name){
$this->link = mysqli_connect($db_host, $db_user, $db_pass);
mysqli_select_db($this->link, $db_name);
}
/* RUN ANY QUERY AGAINST THE DATABASE */
public function QUERY($sql){
$this->results = mysqli_query($this->link, $sql);
$this->num_rows = mysqli_num_rows($this->results);
}
/* RUN ONLY SELECT QUERY */
public function SELECT($sql){
$this->results = mysqli_query($this->link, $sql);
$this->num_rows = mysqli_num_rows($this->results);
}
/* RUN ONLY INSERT QUERY */
public function INSERT($sql){
return $this->results = mysqli_query($this->link, $sql);
}
/* RUN ONLY UPDATE QUERY */
public function UPDATE($sql){
return $this->results = mysqli_query($this->link, $sql);
}
/* RUN ONLY DELETE QUERY */
public function DELETE($sql){
return $this->results = mysqli_query($this->link, $sql);
}
/* RETURNS COUNT OF RESULTS FROM DATABASE */
public function NUM_ROWS(){
return $this->num_rows;
}
/* RETURNS RESULTS IN OBJECT FROM DATABASE */
public function FETCH_OBJECT(){
$rows = array();
for ($x = 0; $x < $this->num_rows(); $x++){
$rows[] = mysqli_fetch_object($this->results);
}
return $rows;
}
/* RETURNS RESULTS IN ASSOC FROM DATABASE */
public function FETCH_ARRAY(){
$rows = array();
for ($x = 0; $x < $this->num_rows(); $x++){
$rows[] = mysqli_fetch_array($this->results);
}
return $rows;
}
/* RETURNS RESULTS IN ASSOC FROM DATABASE */
public function FETCH_ASSOC(){
$rows = array();
for ($x = 0; $x < $this->num_rows(); $x++){
$rows[] = mysqli_fetch_assoc($this->results);
}
return $rows;
}
/* RETURNS RESULTS IN ROW FROM DATABASE */
public function FETCH_ROW(){
$rows = array();
for ($x = 0; $x < $this->num_rows(); $x++){
$rows[] = mysqli_fetch_row($this->results);
}
return $rows;
}
/* RETURNS RESULTS IN ROW COUNT FROM DATABASE */
public function ROW_COUNT(){
$rows = array();
for ($x = 0; $x < $this->num_rows(); $x++){
$row[] = mysqli_fetch_row($this->results);
}
return $row;
}
/* RETURNS ID OF THE LAST QUERY FROM THE INSERT QUERY */
public function INSERT_ID(){
return $this->results = mysqli_insert_id($this->link);
}
/* ESCAPES DATA BEFORE INSERTING INTO DATABASE TO PREVENT INJECTIONS */
public function ESCAPE($field){
$field = secure_xss($field);
return mysqli_real_escape_string($this->link,$field);
}
}
function get_table( $table_name = "" ){
global $table_prefix;
return $table_prefix.$table_name;
}
/* Instantiating a class */
$db = new database($db_host, $db_user,$db_pass, $db_name);
?>