PageRenderTime 53ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/app/class.engine.php

https://github.com/NoVatutz/RevCMS
PHP | 134 lines | 104 code | 27 blank | 3 comment | 6 complexity | d0e7d571322c539b73669eb6d7ecab23 MD5 | raw file
  1. <?php
  2. namespace Revolution;
  3. class engine
  4. {
  5. private $initiated;
  6. private $connected;
  7. private $connection;
  8. final public function Initiate()
  9. {
  10. global $_CONFIG;
  11. if(!$this->initiated)
  12. {
  13. $this->setMySQL('connect', @mysql_connect);
  14. $this->setMySQL('pconnect', @mysql_pconnect);
  15. $this->setMysql('select_db', @mysql_select_db);
  16. $this->setMySQL('query', @mysql_query);
  17. $this->setMySQL('num_rows', @mysql_num_rows);
  18. $this->setMySQL('fetch_assoc', @mysql_fetch_assoc);
  19. $this->setMySQL('fetch_array', @mysql_fetch_array);
  20. $this->setMySQL('result', @mysql_result);
  21. $this->setMySQL('free_result', @mysql_free_result);
  22. $this->setMySQL('escape_string', @mysql_real_escape_string);
  23. $this->initiated = true;
  24. $this->connect($_CONFIG['mysql']['connection_type']);
  25. }
  26. }
  27. final public function setMySQL($key, $value)
  28. {
  29. $this->mysql[$key] = $value;
  30. }
  31. /*-------------------------------Manage Connection-------------------------------------*/
  32. final public function connect($type)
  33. {
  34. global $core, $_CONFIG;
  35. if(!$this->connected)
  36. {
  37. $this->connection = $this->mysql[$type]($_CONFIG['mysql']['hostname'], $_CONFIG['mysql']['username'], $_CONFIG['mysql']['password']);
  38. if($this->connection)
  39. {
  40. $mydatabase = $this->mysql['select_db']($_CONFIG['mysql']['database'], $this->connection);
  41. if($mydatabase)
  42. {
  43. $this->connected = true;
  44. }
  45. else
  46. {
  47. $core->systemError('MySQL Engine', 'MySQL could not connect to database');
  48. }
  49. }
  50. else
  51. {
  52. $core->systemError('MySQL Engine', 'MySQL could not connect to host');
  53. }
  54. }
  55. }
  56. final public function disconnect()
  57. {
  58. global $core;
  59. if($this->connected)
  60. {
  61. if($this->mysql['close'])
  62. {
  63. $this->connected = false;
  64. }
  65. else
  66. {
  67. $core->systemError('MySQL Engine', 'MySQL could not disconnect.');
  68. }
  69. }
  70. }
  71. /*-------------------------------Secure MySQL variables-------------------------------------*/
  72. final public function secure($var)
  73. {
  74. return $this->mysql['escape_string'](stripslashes(htmlspecialchars($var)));
  75. }
  76. /*-------------------------------Manage MySQL queries-------------------------------------*/
  77. final public function query($sql)
  78. {
  79. return $this->mysql['query']($sql, $this->connection);
  80. }
  81. final public function num_rows($sql)
  82. {
  83. global $core;
  84. return $this->mysql['num_rows']($this->mysql['query']($sql, $this->connection));
  85. }
  86. final public function result($sql)
  87. {
  88. global $core;
  89. return $this->mysql['result']($this->mysql['query']($sql, $this->connection), 0);
  90. }
  91. final public function free_result($sql)
  92. {
  93. global $core;
  94. return $this->mysql['free_result']($sql);
  95. }
  96. final public function fetch_array($sql)
  97. {
  98. global $core;
  99. return $this->mysql['fetch_array']($this->mysql['query']($sql, $this->connection), MYSQL_ASSOC);
  100. }
  101. final public function fetch_assoc($sql)
  102. {
  103. global $core;
  104. return $this->mysql['fetch_assoc']($this->mysql['query']($sql, $this->connection));
  105. }
  106. }
  107. ?>