Запросы 1.7 и 1.8 на 1.8 moons.

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Запросы 1.7 и 1.8 на 1.8 moons.

      Кратко: сделав это 70% запросов 1.7 будет работать на 1.8.
      Step 1.
      Прописать в самом вверху это:

      Source Code: game.php

      1. define('DATABASE_VERSION', 'OLD');

      Step 2.
      Все выделить, и вместо старого кода вставить это:

      PHP Source Code: includes\classes\Database.class

      1. <?php
      2. /**
      3. * 2Moons
      4. * by Yaro2709 (2019)
      5. */
      6. class Database
      7. {
      8. protected $dbHandle = NULL;
      9. protected $dbTableNames = array();
      10. protected $lastInsertId = false;
      11. protected $rowCount = false;
      12. protected $queryCounter = 0;
      13. protected static $instance = NULL;
      14. public static function get()
      15. {
      16. if (!isset(self::$instance))
      17. self::$instance = new self();
      18. return self::$instance;
      19. }
      20. public function getDbTableNames()
      21. {
      22. return $this->dbTableNames;
      23. }
      24. private function __clone()
      25. {
      26. }
      27. protected function __construct()
      28. {
      29. $database = array();
      30. require 'includes/config.php';
      31. //Connect
      32. $db = new PDO("mysql:host=".$database['host'].";port=".$database['port'].";dbname=".$database['databasename'], $database['user'], $database['userpw'], array(
      33. PDO::MYSQL_ATTR_INIT_COMMAND => "SET CHARACTER SET utf8, NAMES utf8, sql_mode = 'STRICT_ALL_TABLES'"
      34. ));
      35. //error behaviour
      36. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      37. $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
      38. // $db->query("set character set utf8");
      39. // $db->query("set names utf8");
      40. // $db->query("SET sql_mode = 'STRICT_ALL_TABLES'");
      41. $this->dbHandle = $db;
      42. $dbTableNames = array();
      43. include 'includes/dbtables.php';
      44. foreach($dbTableNames as $key => $name)
      45. {
      46. $this->dbTableNames['keys'][] = '%%'.$key.'%%';
      47. $this->dbTableNames['names'][] = $name;
      48. }
      49. }
      50. public function disconnect()
      51. {
      52. $this->dbHandle = NULL;
      53. }
      54. public function getHandle()
      55. {
      56. return $this->dbHandle;
      57. }
      58. public function lastInsertId()
      59. {
      60. return $this->lastInsertId;
      61. }
      62. public function rowCount()
      63. {
      64. return $this->rowCount;
      65. }
      66. protected function _query($qry, array $params, $type)
      67. {
      68. if (in_array($type, array("insert", "select", "update", "delete", "replace")) === false)
      69. {
      70. throw new Exception("Unsupported Query Type");
      71. }
      72. $this->lastInsertId = false;
      73. $this->rowCount = false;
      74. $qry = str_replace($this->dbTableNames['keys'], $this->dbTableNames['names'], $qry);
      75. /** @var $stmt PDOStatement */
      76. $stmt = $this->dbHandle->prepare($qry);
      77. if (isset($params[':limit']) || isset($params[':offset']))
      78. {
      79. foreach($params as $param => $value)
      80. {
      81. if($param == ':limit' || $param == ':offset')
      82. {
      83. $stmt->bindValue($param, (int) $value, PDO::PARAM_INT);
      84. }
      85. else
      86. {
      87. $stmt->bindValue($param, (int) $value, PDO::PARAM_STR);
      88. }
      89. }
      90. }
      91. try {
      92. $success = (count($params) !== 0 && !isset($params[':limit']) && !isset($params[':offset'])) ? $stmt->execute($params) : $stmt->execute();
      93. }
      94. catch (PDOException $e) {
      95. throw new Exception($e->getMessage()."<br>\r\n<br>\r\nQuery-Code:".str_replace(array_keys($params), array_values($params), $qry));
      96. }
      97. $this->queryCounter++;
      98. if (!$success)
      99. return false;
      100. if ($type === "insert")
      101. $this->lastInsertId = $this->dbHandle->lastInsertId();
      102. $this->rowCount = $stmt->rowCount();
      103. return ($type === "select") ? $stmt : true;
      104. }
      105. protected function getQueryType($qry)
      106. {
      107. if(!preg_match('!^(\S+)!', $qry, $match))
      108. {
      109. throw new Exception("Invalid query $qry!");
      110. }
      111. if(!isset($match[1]))
      112. {
      113. throw new Exception("Invalid query $qry!");
      114. }
      115. return strtolower($match[1]);
      116. }
      117. public function delete($qry, array $params = array())
      118. {
      119. if (($type = $this->getQueryType($qry)) !== "delete")
      120. throw new Exception("Incorrect Delete Query");
      121. return $this->_query($qry, $params, $type);
      122. }
      123. public function replace($qry, array $params = array())
      124. {
      125. if (($type = $this->getQueryType($qry)) !== "replace")
      126. throw new Exception("Incorrect Replace Query");
      127. return $this->_query($qry, $params, $type);
      128. }
      129. public function update($qry, array $params = array())
      130. {
      131. if (($type = $this->getQueryType($qry)) !== "update")
      132. throw new Exception("Incorrect Update Query");
      133. return $this->_query($qry, $params, $type);
      134. }
      135. public function insert($qry, array $params = array())
      136. {
      137. if (($type = $this->getQueryType($qry)) !== "insert")
      138. throw new Exception("Incorrect Insert Query");
      139. return $this->_query($qry, $params, $type);
      140. }
      141. public function select($qry, array $params = array())
      142. {
      143. if (($type = $this->getQueryType($qry)) !== "select")
      144. throw new Exception("Incorrect Select Query");
      145. $stmt = $this->_query($qry, $params, $type);
      146. return $stmt->fetchAll(PDO::FETCH_ASSOC);
      147. }
      148. public function selectSingle($qry, array $params = array(), $field = false)
      149. {
      150. if (($type = $this->getQueryType($qry)) !== "select")
      151. throw new Exception("Incorrect Select Query");
      152. $stmt = $this->_query($qry, $params, $type);
      153. $res = $stmt->fetch(PDO::FETCH_ASSOC);
      154. return ($field === false || is_null($res)) ? $res : $res[$field];
      155. }
      156. /**
      157. * Lists column values of a table
      158. * with desired key from the
      159. * database as an array.
      160. *
      161. * @param string $table
      162. * @param string $column
      163. * @param string|null $key
      164. * @return array
      165. */
      166. public function lists($table, $column, $key = null)
      167. {
      168. $selects = implode(', ', is_null($key) ? array($column) : array($column, $key));
      169. $qry = "SELECT {$selects} FROM %%{$table}%%;";
      170. $stmt = $this->_query($qry, array(), 'select');
      171. $results = array();
      172. if (is_null($key))
      173. {
      174. while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
      175. {
      176. $results[] = $row[$column];
      177. }
      178. }
      179. else
      180. {
      181. while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
      182. {
      183. $results[$row[$key]] = $row[$column];
      184. }
      185. }
      186. return $results;
      187. }
      188. public function query($qry)
      189. {
      190. $this->lastInsertId = false;
      191. $this->rowCount = false;
      192. $this->rowCount = $this->dbHandle->exec($qry);
      193. $this->queryCounter++;
      194. }
      195. public function nativeQuery($qry)
      196. {
      197. $this->lastInsertId = false;
      198. $this->rowCount = false;
      199. $qry = str_replace($this->dbTableNames['keys'], $this->dbTableNames['names'], $qry);
      200. /** @var $stmt PDOStatement */
      201. $stmt = $this->dbHandle->query($qry);
      202. $this->rowCount = $stmt->rowCount();
      203. $this->queryCounter++;
      204. return in_array($this->getQueryType($qry), array('select', 'show')) ? $stmt->fetchAll(PDO::FETCH_ASSOC) : true;
      205. }
      206. public function getQueryCounter()
      207. {
      208. return $this->queryCounter;
      209. }
      210. static public function formatDate($time)
      211. {
      212. return date('Y-m-d H:i:s', $time);
      213. }
      214. public function quote($str)
      215. {
      216. return $this->dbHandle->quote($str);
      217. }
      218. }
      Display All