Created
February 3, 2018 12:00
-
-
Save vietlubu/7d2b1ccffa89386127720ee355da1d5c to your computer and use it in GitHub Desktop.
monsters.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$servername = "localhost"; | |
$username = "root"; | |
$password = "root"; | |
$database = "rathena"; | |
try { | |
$conn = new PDO("mysql:host=$servername;dbname=$database", $username, $password); | |
// set the PDO error mode to exception | |
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
echo "Connected successfully\n"; | |
$sql = "SELECT | |
id, | |
-- UPPER(Sprite) AS Sprite, | |
-- UPPER(kName) AS kName, | |
UPPER(iName) AS iName , | |
iName AS name, | |
LV, HP, SP, EXP, JEXP, Element, MEXP | |
FROM `mob_db_re`"; | |
$stmt = $conn->prepare($sql); | |
$stmt->execute(); | |
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC); | |
$monsters = $stmt->fetchAll(); | |
$dataMonsters = []; | |
foreach ($monsters as $index => $monster) { | |
$dataMonsters[$index]['id'] = $monster['id']; | |
// $dataMonsters[$index]['Sprite'] = $monster['Sprite']; | |
// $dataMonsters[$index]['kName'] = $monster['kName']; | |
$dataMonsters[$index]['iName'] = $monster['iName']; | |
$dataMonsters[$index]['name'] = $monster['name']; | |
$dataMonsters[$index]['LV'] = $monster['LV']; | |
$dataMonsters[$index]['HP'] = $monster['HP']; | |
$dataMonsters[$index]['SP'] = $monster['SP']; | |
$dataMonsters[$index]['EXP'] = $monster['EXP']; | |
$dataMonsters[$index]['JEXP'] = $monster['JEXP']; | |
$dataMonsters[$index]['Element'] = $monster['Element']; | |
$dataMonsters[$index]['MEXP'] = $monster['MEXP']; | |
} | |
$jsonMonsters = json_encode($dataMonsters); | |
file_put_contents('json/monsters.json', $jsonMonsters); | |
// print_r($jsonMonsters); | |
} catch(PDOException $e) { | |
echo "Connection failed: " . $e->getMessage(); | |
} | |
$conn = null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment