Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Revolution MySQL engine
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Weasel" data-source="post: 191552" data-attributes="member: 9520"><p>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, <a href="http://devbest.com/members/kryptos.540/" target="_blank">Kryptos</a>. The only thing I did is adding some slight improvements and commenting.</p><p> </p><p>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.</p><p> </p><p>If you have any questions, just leave a reply. This is OOP.</p><p> </p><p>[PHP]<?</p><p>// Engine made by Kryptos for RevCMS 1.9.x</p><p> </p><p>class engine</p><p>{</p><p>private $initiated;</p><p>private $connected;</p><p>private $connection;</p><p> </p><p>final public function Initiate()</p><p>{</p><p>global $_CONFIG;</p><p>if(!$this->initiated)</p><p>{</p><p>$this->setMySQL('connect', @mysql_connect);</p><p>$this->setMySQL('pconnect', @mysql_pconnect);</p><p>$this->setMysql('select_db', @mysql_select_db);</p><p>$this->setMySQL('query', @mysql_query);</p><p>$this->setMySQL('num_rows', @mysql_num_rows);</p><p>$this->setMySQL('fetch_assoc', @mysql_fetch_assoc);</p><p>$this->setMySQL('fetch_array', @mysql_fetch_array);</p><p>$this->setMySQL('result', @mysql_result);</p><p>$this->setMySQL('free_result', @mysql_free_result);</p><p>$this->setMySQL('escape_string', @mysql_real_escape_string);</p><p> </p><p>$this->initiated = true;</p><p> </p><p>$this->connect($_CONFIG['mysql']['connection_type']);</p><p>}</p><p>}</p><p> </p><p>final public function setMySQL($key, $value)</p><p>{</p><p>$this->mysql[$key] = $value;</p><p>}</p><p> </p><p> </p><p>// Connects to the MySQL database</p><p>final public function connect($type)</p><p>{</p><p>global $_CONFIG;</p><p>if(!$this->connected)</p><p>{</p><p>$this->connection = $this->mysql[$type]($_CONFIG['mysql']['hostname'], $_CONFIG['mysql']['username'], $_CONFIG['mysql']['password']);</p><p> </p><p>if($this->connection)</p><p>{</p><p>$mydatabase = $this->mysql['select_db']($_CONFIG['mysql']['database'], $this->connection);</p><p> </p><p>if($mydatabase)</p><p>{</p><p>$this->connected = true;</p><p>}</p><p>else</p><p>{</p><p>$this->systemError('MySQL Engine', 'MySQL could not connect to database');</p><p>}</p><p>}</p><p>else</p><p>{</p><p>$this->systemError('MySQL Engine', 'MySQL could not connect to host');</p><p>}</p><p>}</p><p>}</p><p> </p><p>// Disconnects the MySQL connection</p><p>final public function disconnect()</p><p>{</p><p>if($this->connected)</p><p>{</p><p>if($this->mysql['close'])</p><p>{</p><p>$this->connected = false;</p><p>}</p><p>else</p><p>{</p><p>$this->systemError('MySQL Engine', 'MySQL could not disconnect.');</p><p>}</p><p>}</p><p>}</p><p> </p><p>/* Secure MySQL variables */</p><p> </p><p>final public function secure($var)</p><p>{</p><p>return $this->mysql['escape_string'](stripslashes(htmlspecialchars($var)));</p><p>}</p><p> </p><p>/* Manage MySQL queries */</p><p>// Usage example: $engine->query("SELECT * FROM users WHERE id='1'")</p><p>final public function query($sql)</p><p>{</p><p>return $this->mysql['query']($sql, $this->connection);</p><p>}</p><p> </p><p>// Usage example: </p><p>// $query = $engine->query("SELECT * FROM users WHERE id='1'")</p><p>// $engine->num_rows($query)</p><p>final public function num_rows($sql)</p><p>{</p><p>return $this->mysql['num_rows']($this->mysql['query']($sql, $this->connection));</p><p>}</p><p> </p><p>// Usage example: </p><p>// $query = $engine->query("SELECT * FROM users WHERE id='1'")</p><p>// $engine->result($query)</p><p>final public function result($sql)</p><p>{</p><p>return $this->mysql['result']($this->mysql['query']($sql, $this->connection), 0);</p><p>}</p><p> </p><p>// Usage example: $engine->free_result("SELECT * FROM users WHERE id='1' LIMIT 1")</p><p>final public function free_result($sql)</p><p>{</p><p>return $this->mysql['free_result']($sql);</p><p>}</p><p> </p><p>// Usage example: </p><p>// $query = $engine->query("SELECT * FROM users WHERE id='1'")</p><p>// $engine->fetch_array($query)</p><p>final public function fetch_array($sql)</p><p>{</p><p>return $this->mysql['fetch_array']($this->mysql['query']($sql, $this->connection), MYSQL_ASSOC);</p><p>}</p><p> </p><p>// Usage example: </p><p>// $query = $engine->query("SELECT * FROM users WHERE id='1'")</p><p>// $engine->fetch_assoc($query)</p><p>final public function fetch_assoc($sql)</p><p>{</p><p>return $this->mysql['fetch_assoc']($this->mysql['query']($sql, $this->connection));</p><p>}</p><p> </p><p>/* In case of a error, you can use this function */</p><p>final public function systemError($where, $errorMessage)</p><p>{</p><p>die(</p><p>'<center><b>Revolution Engine reported an error.</b><br /> <br />' .</p><p>'<b>Where:</b> ' . $where . ' <br /> ' .</p><p>'<b>Message:</b> ' . $errorMessage . '</center>'</p><p>);</p><p>}</p><p>}</p><p>?>[/PHP]</p></blockquote><p></p>
[QUOTE="Weasel, post: 191552, member: 9520"] 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, [URL='http://devbest.com/members/kryptos.540/']Kryptos[/URL]. 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>' ); } } ?>[/PHP] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Revolution MySQL engine
Top