Weasel
👄 I'd intercept me
First of all, please note that this is taken from RevCMS 1.9.x, hence the name Revolution. All credits go to the maker of this,
The reason I am re-releasing this is because I think Kryptos did a great job on this, and if you just start with OOP coding, it is a great MySQL engine.
If you have any questions, just leave a reply. This is OOP.
You must be registered for see links
. The only thing I did is adding some slight improvements and commenting.The reason I am re-releasing this is because I think Kryptos did a great job on this, and if you just start with OOP coding, it is a great MySQL engine.
If you have any questions, just leave a reply. This is OOP.
PHP:
<?
// Engine made by Kryptos for RevCMS 1.9.x
class engine
{
private $initiated;
private $connected;
private $connection;
final public function Initiate()
{
global $_CONFIG;
if(!$this->initiated)
{
$this->setMySQL('connect', @mysql_connect);
$this->setMySQL('pconnect', @mysql_pconnect);
$this->setMysql('select_db', @mysql_select_db);
$this->setMySQL('query', @mysql_query);
$this->setMySQL('num_rows', @mysql_num_rows);
$this->setMySQL('fetch_assoc', @mysql_fetch_assoc);
$this->setMySQL('fetch_array', @mysql_fetch_array);
$this->setMySQL('result', @mysql_result);
$this->setMySQL('free_result', @mysql_free_result);
$this->setMySQL('escape_string', @mysql_real_escape_string);
$this->initiated = true;
$this->connect($_CONFIG['mysql']['connection_type']);
}
}
final public function setMySQL($key, $value)
{
$this->mysql[$key] = $value;
}
// Connects to the MySQL database
final public function connect($type)
{
global $_CONFIG;
if(!$this->connected)
{
$this->connection = $this->mysql[$type]($_CONFIG['mysql']['hostname'], $_CONFIG['mysql']['username'], $_CONFIG['mysql']['password']);
if($this->connection)
{
$mydatabase = $this->mysql['select_db']($_CONFIG['mysql']['database'], $this->connection);
if($mydatabase)
{
$this->connected = true;
}
else
{
$this->systemError('MySQL Engine', 'MySQL could not connect to database');
}
}
else
{
$this->systemError('MySQL Engine', 'MySQL could not connect to host');
}
}
}
// Disconnects the MySQL connection
final public function disconnect()
{
if($this->connected)
{
if($this->mysql['close'])
{
$this->connected = false;
}
else
{
$this->systemError('MySQL Engine', 'MySQL could not disconnect.');
}
}
}
/* Secure MySQL variables */
final public function secure($var)
{
return $this->mysql['escape_string'](stripslashes(htmlspecialchars($var)));
}
/* Manage MySQL queries */
// Usage example: $engine->query("SELECT * FROM users WHERE id='1'")
final public function query($sql)
{
return $this->mysql['query']($sql, $this->connection);
}
// Usage example:
// $query = $engine->query("SELECT * FROM users WHERE id='1'")
// $engine->num_rows($query)
final public function num_rows($sql)
{
return $this->mysql['num_rows']($this->mysql['query']($sql, $this->connection));
}
// Usage example:
// $query = $engine->query("SELECT * FROM users WHERE id='1'")
// $engine->result($query)
final public function result($sql)
{
return $this->mysql['result']($this->mysql['query']($sql, $this->connection), 0);
}
// Usage example: $engine->free_result("SELECT * FROM users WHERE id='1' LIMIT 1")
final public function free_result($sql)
{
return $this->mysql['free_result']($sql);
}
// Usage example:
// $query = $engine->query("SELECT * FROM users WHERE id='1'")
// $engine->fetch_array($query)
final public function fetch_array($sql)
{
return $this->mysql['fetch_array']($this->mysql['query']($sql, $this->connection), MYSQL_ASSOC);
}
// Usage example:
// $query = $engine->query("SELECT * FROM users WHERE id='1'")
// $engine->fetch_assoc($query)
final public function fetch_assoc($sql)
{
return $this->mysql['fetch_assoc']($this->mysql['query']($sql, $this->connection));
}
/* In case of a error, you can use this function */
final public function systemError($where, $errorMessage)
{
die(
'<center><b>Revolution Engine reported an error.</b><br /> <br />' .
'<b>Where:</b> ' . $where . ' <br /> ' .
'<b>Message:</b> ' . $errorMessage . '</center>'
);
}
}
?>