Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3.  
  4. namespace Revolution;
  5. if(!defined('IN_INDEX')) { die('Sorry, you cannot access this file.'); }
  6. class engine
  7. {
  8. private $initiated;
  9. private $connected;
  10.  
  11. private $connection;
  12.  
  13.  
  14. final public function Initiate()
  15. {
  16. global $_CONFIG;
  17. if(!$this->initiated)
  18. {
  19. $this->setMySQL('connect', mysql_connect);
  20. $this->setMySQL('pconnect', mysql_pconnect);
  21. $this->setMysql('select_db', mysql_select_db);
  22. $this->setMySQL('query', mysql_query);
  23. $this->setMySQL('num_rows', mysql_num_rows);
  24. $this->setMySQL('fetch_assoc', mysql_fetch_assoc);
  25. $this->setMySQL('fetch_array',mysql_fetch_array);
  26. $this->setMySQL('result', mysql_result);
  27. $this->setMySQL('free_result', mysql_free_result);
  28. $this->setMySQL('escape_string', mysql_real_escape_string);
  29.  
  30. $this->initiated = true;
  31.  
  32. $this->connect($_CONFIG['mysql']['connection_type']);
  33. }
  34. }
  35.  
  36. final public function setMySQL($key, $value)
  37. {
  38. $this->mysql[$key] = $value;
  39. }
  40.  
  41.  
  42. /*-------------------------------Manage Connection-------------------------------------*/
  43.  
  44. final public function connect($type)
  45. {
  46. global $core, $_CONFIG;
  47. if(!$this->connected)
  48. {
  49. $this->connection = $this->mysql[$type]($_CONFIG['mysql']['hostname'], $_CONFIG['mysql']['username'], $_CONFIG['mysql']['password']);
  50.  
  51. if($this->connection)
  52. {
  53. $mydatabase = $this->mysql['select_db']($_CONFIG['mysql']['database'], $this->connection);
  54.  
  55. if($mydatabase)
  56. {
  57. $this->connected = true;
  58. }
  59. else
  60. {
  61. $core->systemError('MySQL Engine', 'MySQL could not connect to database');
  62. }
  63. }
  64. else
  65. {
  66. $core->systemError('MySQL Engine', 'MySQL could not connect to host');
  67. }
  68. }
  69. }
  70.  
  71. final public function disconnect()
  72. {
  73. global $core;
  74. if($this->connected)
  75. {
  76. if($this->mysql['close'])
  77. {
  78. $this->connected = false;
  79. }
  80. else
  81. {
  82. $core->systemError('MySQL Engine', 'MySQL could not disconnect.');
  83. }
  84. }
  85. }
  86.  
  87. /*-------------------------------Secure MySQL variables-------------------------------------*/
  88.  
  89. final public function secure($var)
  90. {
  91. return $this->mysql['escape_string'](stripslashes(htmlspecialchars($var)));
  92. }
  93.  
  94. /*-------------------------------Manage MySQL queries-------------------------------------*/
  95.  
  96. final public function query($sql)
  97. {
  98. return $this->mysql['query']($sql, $this->connection) or die(mysql_error());
  99. }
  100.  
  101. final public function num_rows($sql)
  102. {
  103. return $this->mysql['num_rows']($this->mysql['query']($sql, $this->connection));
  104. }
  105.  
  106. final public function result($sql)
  107. {
  108. return $this->mysql['result']($this->mysql['query']($sql, $this->connection), 0);
  109. }
  110.  
  111. final public function free_result($sql)
  112. {
  113. return $this->mysql['free_result']($sql);
  114. }
  115.  
  116. final public function fetch_array($sql)
  117. {
  118. $query = $this->mysql['query']($sql, $this->connection);
  119.  
  120. $data = array();
  121.  
  122. while($row = $this->mysql['fetch_array']($query))
  123. {
  124. $data[] = $row;
  125. }
  126.  
  127. return $data;
  128. }
  129.  
  130. final public function fetch_assoc($sql)
  131. {
  132. return $this->mysql['fetch_assoc']($this->mysql['query']($sql, $this->connection));
  133. }
  134.  
  135.  
  136.  
  137.  
  138. }
  139. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement