properties.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. $properties = json_decode( '{
  3. "level": 95,
  4. "gender": "Female",
  5. "player_id": 12345,
  6. "name": "Unknown",
  7. "personalstats": {
  8. "useractivity": 26817266,
  9. "logins": 4361,
  10. "weaponsbought": 11148,
  11. "attackmisses": 23141,
  12. "attackdamage": 59342703,
  13. "attackhits": 52840,
  14. "axehits": 1067,
  15. "attackswon": 14058,
  16. "highestbeaten": 100,
  17. "bestkillstreak": 504,
  18. "jailed": 306,
  19. "mailssent": 1724,
  20. "attackcriticalhits": 10817,
  21. "slahits": 425,
  22. "moneymugged": 19552798251,
  23. "largestmug": 1000026663,
  24. "friendmailssent": 375,
  25. "roundsfired": 271152,
  26. "pishits": 346,
  27. "defendswon": 2765,
  28. "hospital": 8385,
  29. "defendslost": 3707,
  30. "rifhits": 6620,
  31. "attackslost": 797,
  32. "attacksassisted": 336,
  33. "attacksstealthed": 8335,
  34. "onehitkills": 6547,
  35. "dumpsearches": 1026,
  36. "dumpfinds": 1026,
  37. "itemsdumped": 5050,
  38. "itemssent": 3567,
  39. "drugsused": 5352,
  40. "cantaken": 77,
  41. "auctionswon": 16,
  42. "daysbeendonator": 1881,
  43. "spousemailssent": 104,
  44. "medicalitemsused": 21720,
  45. "companymailssent": 185,
  46. "trainsreceived": 1071,
  47. "cityfinds": 522,
  48. "theyrunaway": 1022,
  49. "failedbusts": 249,
  50. "peoplebusted": 3000,
  51. "pointsbought": 44095,
  52. "itemsbought": 3426,
  53. "xantaken": 4812,
  54. "traveltimes": 3475,
  55. "mextravel": 481,
  56. "itemsboughtabroad": 92754,
  57. "cantravel": 462,
  58. "lontravel": 387,
  59. "caytravel": 411,
  60. "argtravel": 350,
  61. "hawtravel": 165,
  62. "japtravel": 132,
  63. "switravel": 586,
  64. "soutravel": 133,
  65. "dubtravel": 172,
  66. "chitravel": 196,
  67. "shrtaken": 50,
  68. "shohits": 157,
  69. "piehits": 4646,
  70. "bountiescollected": 798,
  71. "totalbountyreward": 210769630,
  72. "medstolen": 8,
  73. "attacksdraw": 218,
  74. "virusescoded": 125,
  75. "yourunaway": 157,
  76. "victaken": 84,
  77. "overdosed": 108,
  78. "revivesreceived": 805,
  79. "auctionsells": 15,
  80. "exttaken": 246,
  81. "kettaken": 50,
  82. "respectforfaction": 76338,
  83. "smghits": 1663,
  84. "bountiesreceived": 206,
  85. "factionmailssent": 173,
  86. "peoplebought": 502,
  87. "peopleboughtspent": 54974080,
  88. "chahits": 234,
  89. "machits": 119,
  90. "heahits": 697,
  91. "networth": 30897667775,
  92. "grehits": 276,
  93. "missioncreditsearned": 40942,
  94. "contractscompleted": 1022,
  95. "dukecontractscompleted": 1022,
  96. "revives": 663,
  97. "missionscompleted": 1,
  98. "bountiesplaced": 486,
  99. "totalbountyspent": 194793585,
  100. "bloodwithdrawn": 5140,
  101. "lsdtaken": 11,
  102. "defendsstalemated": 28,
  103. "meritsbought": 45,
  104. "opitaken": 14,
  105. "nerverefills": 1409,
  106. "consumablesused": 24693,
  107. "candyused": 1838,
  108. "alcoholused": 13823,
  109. "energydrinkused": 9032,
  110. "tokenrefills": 201,
  111. "organisedcrimes": 158,
  112. "booksread": 10,
  113. "h2hhits": 147,
  114. "classifiedadsplaced": 6,
  115. "traveltime": 37998600,
  116. "unarmoredwon": 259,
  117. "stockpayouts": 487,
  118. "boostersused": 1189,
  119. "territorytime": 2631552,
  120. "rehabs": 6667,
  121. "rehabcost": 1404830000,
  122. "awards": 462,
  123. "statenhancersused": 5,
  124. "bestdamage": 11472,
  125. "racingpointsearned": 2126,
  126. "raceswon": 699,
  127. "racesentered": 2395,
  128. "receivedbountyvalue": 88109384,
  129. "pcptaken": 1,
  130. "cityitemsbought": 85276,
  131. "specialammoused": 10977,
  132. "spetaken": 1,
  133. "hollowammoused": 4000,
  134. "tracerammoused": 2498,
  135. "incendiaryammoused": 2493,
  136. "piercingammoused": 1986,
  137. "refills": 1612
  138. },
  139. "status": {
  140. "description": "Okay",
  141. "details": "",
  142. "state": "Okay",
  143. "color": "green",
  144. "until": 0
  145. }
  146. }');
  147. print( "<pre>" );
  148. print_r( $properties );
  149. print( "</pre>");
  150. $list = [];
  151. foreach ( $properties as $key => $val ) {
  152. if ( is_object( $val ) ) {
  153. foreach( $val as $subkey => $subval) {
  154. $list[] = [$subkey, $key];
  155. }
  156. } else {
  157. $list[] = [$key, ''];
  158. }
  159. }
  160. print("<pre>");
  161. print_r( $list );
  162. print("</pre>");
  163. $pdo = null;
  164. try {
  165. $pdo = new PDO("sqlite:" . './slork.sqlite');
  166. } catch (PDOException $e) {
  167. // handle the exception here
  168. }
  169. if ( !$pdo ) {
  170. exit( "Cannot connect to database" );
  171. }
  172. $query = "DROP TABLE IF EXISTS properties;";
  173. $pdo->exec( $query );
  174. $query = <<<QUERY
  175. CREATE TABLE IF NOT EXISTS properties (
  176. id INTEGER PRIMARY KEY, property TEXT, parent TEXT, UNIQUE(property));
  177. QUERY;
  178. $pdo->exec( $query );
  179. $query = "INSERT INTO properties (property, parent) VALUES (?, ?) ON CONFLICT (property) DO NOTHING;";
  180. $stmt = $pdo->prepare( $query );
  181. foreach ( $list as $item ) {
  182. $stmt->execute( $item );
  183. }
  184. /**
  185. $query = "SELECT property FROM properties;";
  186. $stmt = $pdo->query( $query );
  187. foreach( $stmt as $row ) {
  188. print( $row['property'] . ', ');
  189. }
  190. */