RevCMS 1.9.9.9 class.engine.php

Marlboro20

Member
Dec 17, 2013
37
6
RevolutionCMS engine class update
Hello bastards! :D

i am here to share i quick update of revolutionCMS engine class updated to use mysqli instead of mysql
Also i haven't tested this but it should work, Just replace the following code below with your class.engine.php
i also advise you to actually rename your class.engine.php to class.engine.php.bak and make a new file..
Just replace the following code below into your class.engine.php in the app folder!
PHP:
<?php
    /**
     *    Revolution CMS
     *
     *    @author        Kryptos
     *    @author        Marlboro20
     *
     *    A mysqli class for RevolutionCMS
     */
    namespace Revolution;
    use mysqli;

    if(!defined('IN_INDEX'))
    {
    die('Direct access to this file was denied');
    }

    class engine
    {
        protected $connection = null;

        private $_initiated = false;
        private $_connected = false;

        final public function Initiate()
        {
            global $_CONFIG;
       
            if($this->_initiated == false)
            {
                $this->_initiated = true;
                $this->connect($_CONFIG['mysql']['connection_type']);
            }
        }
     
        /**
        * Creates a new database connection
        * @return boolean
        */
        final public function connect($type = 'pconnect')
        {
            global $core, $_CONFIG;
            $connection = (($type == 'pconnect') ? 'p:' : '') . $_CONFIG['mysql']['hostname'];
       
            $this->connection = new mysqli($connection, $_CONFIG['mysql']['username'], $_CONFIG['mysql']['password'], $_CONFIG['mysql']['username'], $_CONFIG['mysql']['database']);
            $this->_connected = true;
       
            if(mysqli_connect_errno())
            {
                $core->systemError('MySQL Engine', mysqli_connect_error());
                $this->_connected = false;
                return $this->_connected;
            }
            $this->connection->set_charset("utf8");
       
            return $this->_connected;
        }
        /**
        * Disconnects the database connection
        * @return void
        */
        final public function disconnect()
        {
            global $core;
       
            if($this->_connected == true || $this->connection !== null)
            {
                $this->connection->close();
                $this->connection = null;
                $this->_connected = false;
            }
        }
        /**
        * Secures a string.
        * @input    string
        * @return    string
        */
        final public function secure($string)
        {
            return $this->connection->real_escape_string(stripslashes(htmlspecialchars($string)));
        }
        /*
        * Runs a query in the database.
        * @returns (object) mysqli object result || False
        */
        final public function query($sql)
        {
            global $core;
       
            if(!$result = $this->connection->query($sql))
            {
                $core->systemError('MySQL Engine', mysqli_error());
            }
            return $result;
        }
        /**
        * Returns the amount of rows in a table.
        * @return (int) row count.
        */
        final public function num_rows($query)
        {
            if($result = $this->query($query))
            {
                return (int) $result->num_rows;
            }
        }
        /**
        * Returns the first row in the array.
        * @return (string) of first array key.
        */
        final public function result($query)
        {
            if($result = $this->fetch_array($query, MYSQLI_NUM))
            {
                return (string) $result[0];
            }
        }
        /**
        * Returns an array of rows from a table in the database.
        * @return (array) $results
        */
        final public function fetch_array($query, $type = MYSQLI_BOTH)
        {
            $results = array();
       
            while($row = $this->query($query)->fetch_array($type))
            {
                $results[] = $row;
            }
       
            return $results;
            $results->free();
        }
        /**
        * Returns an associative array of rows from the database
        * @return (array)(assoc)
        */
        final public function fetch_assoc($query)
        {
            return $this->fetch_array($query, MYSQLI_ASSOC);
        }
    }
?>

If there is anything wrong please message me!
 
Last edited:

Users who are viewing this thread

Top