OOP MYSQLI

GarettM

Posting Freak
Aug 5, 2010
833
136
I Cant Find The Error My PHP Parser.exe says its not secure :'( whats not secure?
PHP:
<?php
    /**
     * RailwayCMS v1
     * HabboCMS copyright [email protected]
     **/
 
class database
{
    private $mysqli;
    
    function __construct($db_host, $db_name, $db_user, $db_password){
        try
        {
            $this->mysqli = new mysqli($db_host, $db_user, $db_password, $db_name);
            
            $this->mysqli->set_charset('utf8');
            
            if(!$this->mysqli) {
                throw new mysqli_sql_exception(mysqli_connect_error());
            }
        }
        catch(mysqli_sql_exception $e)
        {
            printf("Mysqli Couldnt Connect To Host Because : <pre> %s </pre>", $e->getMessage());
            exit;
        }
    }
    public function _query($string)
    {
        try {
            if ($query = $this->mysqli->query($string)) {
                return $query;
            }
            else {
                throw new mysqli_sql_exception($string);
            }
        } catch (mysqli_sql_exception $e)
        {
            printf("Mysql Returned Error <pre> %s </pre>", $e->getMessage());
        }
    }
    public function _get($resource, $field = NULL)
    {
        try {
            if($field == null) {
                $data = array();
                
                while($row = $resource->fetch_arry(MYSQLI_ASSOC)) {
                    $data[] = $row;
                }
            } else {
                $row =  $resource->fetch_array(MYSQLI_BOTH);
                $data = $row[$field];
            }
        $resource->close();
        
        return $data;
        } catch ( mysqli_sql_exception $e ) {
            printf("Mysql Error <pre>%s</pre>", $e->getMessage());
        }
    }
      
    public function DBStatus(){
        return (isset($this->dbc)) ? true : false;
    }
}
 
?>
 

Predict

Active Member
Jun 27, 2011
126
63
I ain't really sure what the problem here is, but if you want a mysqli class, you're free to use the one I'm using for POP CMS.

PHP:
<?php
if(!defined('DH_PAGES'))
{
    die('<h1>Access denied</h1><p>You do not have the privileges to access this webpage.</p>');
}
 
class db_mysqli extends mysqli
{
    public function __construct($host, $user, $pass, $db)
    {
        parent::__construct($host, $user, $pass, $db);
        if (mysqli_connect_error())
        {
            die('<h1>Cannot connect to database</h1><p>There is a problem while connecting to the database, please check back to your database connection settings.</p>');
        }
    }
}
?>
 

Users who are viewing this thread

Top