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
Programming Q&A
Upgrade to mysqli from mysql
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="Proximity" data-source="post: 358359" data-attributes="member: 43026"><p>[code]</p><p><?php</p><p></p><p> namespace XFA;</p><p> if(!defined('IN_INDEX')) { die('Sorry, you cannot access this file.'); }</p><p> class engine {</p><p> private $initiated;</p><p> private $connected;</p><p> private $mysql;</p><p> private $connection;</p><p></p><p> final public function Initiate() {</p><p> global $_CONFIG;</p><p> if(!$this->initiated) {</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> $this->initiated = true;</p><p> $this->connect($_CONFIG['mysql']['connection_type']);</p><p> }</p><p> }</p><p></p><p> final public function setMySQL($key, $value) {</p><p> $this->mysql[$key] = $value;</p><p> }</p><p></p><p> /*-------------------------------Manage Connection-------------------------------------*/</p><p></p><p> final public function connect($type) {</p><p> global $core, $_CONFIG;</p><p> if(!$this->connected) {</p><p> $this->connection = $this->mysql[$type]($_CONFIG['mysql']['hostname'], $_CONFIG['mysql']['username'], $_CONFIG['mysql']['password']); </p><p> if($this->connection) {</p><p> $mydatabase = $this->mysql['select_db']($_CONFIG['mysql']['database'], $this->connection); </p><p> if($mydatabase) {</p><p> $this->connected = true; </p><p> } else {</p><p> $core->systemError('MySQL', 'Can not connect to Database');</p><p> }</p><p> } else {</p><p> $core->systemError('MySQL', 'Can not connect to Host'); </p><p> }</p><p> }</p><p> }</p><p> </p><p> final public function disconnect() {</p><p> global $core;</p><p> if($this->connected) {</p><p> if($this->mysql['close']) {</p><p> $this->connected = false;</p><p> } else {</p><p> $core->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> return $this->mysql['escape_string'](stripslashes(htmlspecialchars($var)));</p><p> } </p><p></p><p> final public function signature($var) {</p><p> return $this->mysql['escape_string']($var);</p><p> }</p><p></p><p> /*-------------------------------Manage MySQL queries-------------------------------------*/</p><p></p><p> final public function query($sql) {</p><p> return $this->mysql['query']($sql, $this->connection) or die(mysql_error());</p><p> }</p><p></p><p> final public function num_rows($sql) {</p><p> return $this->mysql['num_rows']($this->mysql['query']($sql, $this->connection));</p><p> }</p><p></p><p> final public function result($sql) {</p><p> return $this->mysql['result']($this->mysql['query']($sql, $this->connection), 0);</p><p> }</p><p> </p><p> final public function free_result($sql) {</p><p> return $this->mysql['free_result']($sql);</p><p> } </p><p></p><p> final public function fetch_array($sql) {</p><p> $query = $this->mysql['query']($sql, $this->connection); </p><p> $data = array(); </p><p> while($row = $this->mysql['fetch_array']($query)) {</p><p> $data[] = $row;</p><p> }</p><p> return $data;</p><p> }</p><p></p><p> final public function fetch_assoc($sql) {</p><p> return $this->mysql['fetch_assoc']($this->mysql['query']($sql, $this->connection));</p><p> }</p><p> }</p><p></p><p>?></p><p></p><p>[/code]</p></blockquote><p></p>
[QUOTE="Proximity, post: 358359, member: 43026"] [code] <?php namespace XFA; if(!defined('IN_INDEX')) { die('Sorry, you cannot access this file.'); } class engine { private $initiated; private $connected; private $mysql; 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; } /*-------------------------------Manage Connection-------------------------------------*/ final public function connect($type) { global $core, $_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 { $core->systemError('MySQL', 'Can not connect to Database'); } } else { $core->systemError('MySQL', 'Can not connect to Host'); } } } final public function disconnect() { global $core; if($this->connected) { if($this->mysql['close']) { $this->connected = false; } else { $core->systemError('MySQL Engine', 'MySQL could not disconnect.'); } } } /*-------------------------------Secure MySQL variables-------------------------------------*/ final public function secure($var) { return $this->mysql['escape_string'](stripslashes(htmlspecialchars($var))); } final public function signature($var) { return $this->mysql['escape_string']($var); } /*-------------------------------Manage MySQL queries-------------------------------------*/ final public function query($sql) { return $this->mysql['query']($sql, $this->connection) or die(mysql_error()); } final public function num_rows($sql) { return $this->mysql['num_rows']($this->mysql['query']($sql, $this->connection)); } final public function result($sql) { return $this->mysql['result']($this->mysql['query']($sql, $this->connection), 0); } final public function free_result($sql) { return $this->mysql['free_result']($sql); } final public function fetch_array($sql) { $query = $this->mysql['query']($sql, $this->connection); $data = array(); while($row = $this->mysql['fetch_array']($query)) { $data[] = $row; } return $data; } final public function fetch_assoc($sql) { return $this->mysql['fetch_assoc']($this->mysql['query']($sql, $this->connection)); } } ?> [/code] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
Upgrade to mysqli from mysql
Top