Firstly I've been told that I use outdated MySQL, and should use MySQLi, but I'm not entirely sure how to migrate over.
Also, to further explain this API it shows player stats when you search for their name. For some reason in the background it's querying my url/0 and it's making page loading extremely slow.
Anyhow here's my api.php. Could somebody give me an example of MySQLi?
<?php
// EPICMC CMS API
$date1 = new DateTime('NOW');
$date2 = new DateTime('12/12/2014');
$difference = $date1->diff($date2)->days;
$link = mysql_connect("localhost", "username", "password");
mysql_select_db("database", $link);
if ($_GET['task'] == 'total') {
$get_db = 'database';
$result = mysql_query("SELECT * FROM $get_db", $link);
echo '{"task":"total","amount":"';
echo mysql_num_rows($result);
echo '"}';
} elseif ($_GET['task'] == 'info') {
$get_player = $_GET['player'];
$get_db = 'simpleauth_players';
$result = mysql_query("SELECT * FROM $get_db WHERE name = '" . mysql_real_escape_string($get_player) . "'", $link);
while ($data = mysql_fetch_array($result)) {
echo '{"task":"view","registered":"';
echo date('m/d/Y h:i A', $data['registerdate']);
echo '","verified":"';
echo $data['verified'];
echo '","banned":"';
echo $data['banned'];
echo '","locked":"';
echo $data['locked'];
echo '","theme":"';
echo $data['theme'];
echo '","email":"';
echo $data['email'];
echo '","cover":"';
echo $data['cover'];
echo '","ip":"';
echo $data['lastip'];
echo '","lastlogin":"';
echo date('m/d/Y h:i A', $data['logindate']);
echo '","ip":"';
echo $data['lastip'];
echo '"}';
}
} elseif ($_GET['task'] == 'stats') {
$get_player = $_GET['player'];
$get_db = 'player_stats';
$result = mysql_query("SELECT * FROM $get_db WHERE name = '" . mysql_real_escape_string($get_player) . "'", $link);
while ($data = mysql_fetch_array($result)) {
if($data['skin'] == null){
$skin = $data['name'];
} else {
$skin = $data['skin'];
}
echo json_encode(array(
'task' => 'viewstats',
'skin' => $skin,
'deaths' => $data['deaths'],
'kills' => $data['kills'],
'joins' => $data['joins'],
'quits' => $data['quits'],
'kicked' => $data['kicked'],
'places' => $data['places'],
'breaks' => $data['breaks'],
'chats' => $data['chats'],
// then ratio
'ratio' => $data['kills'] / $data['deaths']
));
}
} elseif ($_GET['task'] == 'login') {
$get_user = $_GET['user'];
$get_db = 'simpleauth_players';
$result = mysql_query("SELECT * FROM $get_db WHERE name = '" . mysql_real_escape_string($get_user) . "'", $link);
while ($data = mysql_fetch_array($result)) {
echo '{"task":"login","password":"';
echo $data['hash'];
echo '","lastip":"';
echo $data['lastip'];
echo '","timestamp":"';
echo $data['logindate'];
echo '"}';
}
} else {
echo 'online';
}
function hashME($player, $password)
{
return bin2hex(hash("sha512", $password . strtolower($player), true) ^ hash("whirlpool", strtolower($player) . $password, true));
}
?>