Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. <?php
  2.  
  3. defined( '_ACM_VALID' ) or die( 'Direct Access to this location is not allowed.' );
  4.  
  5. class mysql {
  6.  
  7. private static $_instances = array();
  8.  
  9. private $_m, $_host, $_user, $_pass, $_db, $db_inst;
  10.  
  11. public static function g($id = NULL) {
  12. if (!isset(self::$_instances[$id])) {
  13. $c = __CLASS__;
  14. self::$_instances[$id] = new $c($id);
  15. }
  16. return self::$_instances[$id];
  17. }
  18.  
  19. private function __construct($id) {
  20.  
  21. if(is_null($id)) {
  22. $ls = CONFIG::g()->login_server;
  23. $this->_host = $ls['hostname'];
  24. $this->_user = $ls['user'];
  25. $this->_pass = $ls['password'];
  26. $this->_db = $ls['database'];
  27. }else{
  28. $gs = CONFIG::g()->select_game_server($id);
  29. $this->_host = $gs['hostname'];
  30. $this->_user = $gs['user'];
  31. $this->_pass = $gs['password'];
  32. $this->_db = $gs['database'];
  33. }
  34.  
  35. if(empty($this->_pass))
  36. DEBUG::add('Your configuration file contains settings ('.$this->_user.' with no password) that correspond to the default MySQL privileged account.'.
  37. 'Your MySQL server is running with this default, is open to intrusion, and you really should fix this security hole.', 'red');
  38.  
  39. $this->connect();
  40. }
  41.  
  42. private function connect () {
  43. $this->db_inst = @mysql_connect ($this->_host,$this->_user,$this->_pass);
  44. if(!$this->db_inst) {
  45. MSG::add_error(LANG::i18n('_error_db_connect'));
  46. return false;
  47. }
  48. if(!@mysql_select_db ($this->_db, $this->db_inst)) {
  49. MSG::add_error(LANG::i18n('_error_db_select'));
  50. return false;
  51. }
  52. return true;
  53. }
  54.  
  55. public function query ($q) {
  56. DEBUG::add($this->_db.'->'.$q);
  57. LOGDAEMON::add($this->_db.'->'.$q);
  58. $rslt = @mysql_query ($q, $this->db_inst);
  59. DEBUG::add('Records: '.@mysql_affected_rows());
  60. return $rslt;
  61. }
  62.  
  63. public function result ($q) {
  64. DEBUG::add($this->_db.'->'.$q);
  65. LOGDAEMON::add($this->_db.'->'.$q);
  66. $rslt = @mysql_result (@mysql_query ($q, $this->db_inst), 0);
  67. DEBUG::add('Result: '.gettype($rslt).'('.var_export($rslt, true).')');
  68. return $rslt;
  69. }
  70.  
  71. public function escape_string($q) {
  72. return mysql_real_escape_string($q, $this->db_inst);
  73. }
  74.  
  75. public function __destruct () {
  76. @mysql_close ($this->db_inst);
  77. }
  78. }
  79.  
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement