Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- /**
- *
- * NOTE: Designed for use with PHP version 5.5 and up
- * @author T0niiiiii <t0niiiiii@>
- * @copyright 2016
- * @version: 1.0
- *
- */
- /**
- * Class MySQLI file.
- */
- Class MySql {
- Private $connected;
- Private $connection;
- Public Function __construct($host, $user, $password, $db)
- {
- $this->host = $host;
- $this->db = $db;
- $this->user = $user;
- $this->password = $password;
- $this->connect();
- }
- Private Function connect()
- {
- if(!$this->connected){
- if($this->connection = @new mysqli($this->host, $this->user, $this->password)){
- if($database = $this->connection->select_db($this->db)){
- $this->connection->set_charset("UTF-8");
- $this->connected = true;
- } else {
- return print $this->connection->connect_error;
- }
- } else {
- return print $this->connection->connect_error;
- }
- }
- }
- Private Function disconnect()
- {
- if($this->connected){
- $this->connection->kill($this->connection->thread_id);
- if($this->connection->close()){
- $this->connected = null;
- } else {
- return print $this->connection->connect_error;
- }
- }
- }
- Public Function query($sql)
- {
- return $this->connection->query($sql);
- }
- Public Function result($sql)
- {
- if($this->connected){
- $query = $this->query($sql);
- if($query){
- $result = array();
- $i = 0;
- while($row = $query->fetch_object()){
- $result[$i] = $row;
- $i++;
- }
- return $result;
- } else {
- return print $this->connection->error;
- }
- }
- }
- Public Function result_($sql)
- {
- if($this->connected){
- if($query = $this->query($sql)){
- $result = array();
- while($row = $query->fetch_object()){
- $result[0] = $row;
- }
- return $result;
- } else {
- return print $this->connection->error;
- }
- }
- }
- Public Function secure($data)
- {
- if ($this->connected){
- return $this->connection->real_escape_string(htmlspecialchars(strip_tags(trim($data))));
- }
- return print $this->connection->error;
- }
- Public Function __destruct()
- {
- $this->disconnect();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement