<?php
header('Access-Control-Allow-Origin: *');
 
 
 
 
$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="database"; // Database name
$tbl_name="scores"; // Table name
 
// Connect to server and select database.
$mysqli = new mysqli("$host", "$username", "$password")or die("cannot connect");
$mysqli->select_db("$db_name")or die("cannot select DB");
 
// Retrieve data from database
$sql="SELECT * FROM scores ORDER BY score DESC LIMIT 10";
$result=$mysqli->query($sql);
 
// Start looping rows in mysql database.
while($rows=$result->fetch_array()){
echo $rows['name'] . "|" . $rows['score'] . "|";
 
// close while loop
}
 
// close MySQL connection
$mysqli->close;
?>
<?php
 
 
$db = "database";//Your database name
$dbu = "username";//Your database username
$dbp = "password";//Your database users' password
$host = "localhost";//MySQL server - usually localhost
 
$dblink = new mysqli($host,$dbu,$dbp);
$seldb = $dblink->select_db($db);
 
if(isset($_GET['name']) && isset($_GET['score'])){
 
     //Lightly sanitize the GET's to prevent SQL injections and possible XSS attacks
     $name = strip_tags($dblink->real_escape_string($_GET['name']));
     $score = strip_tags($dblink->real_escape_string($_GET['score']));
     $sql = `name`->query("INSERT INTO `$db`.`scores` (`id`) VALUES ('','$name','$score');");
     
     if($sql){
     
          //The query returned true - now do whatever you like here.
          echo 'Your score was saved. Congrats!';
         
     }else{
     
          //The query returned false - you might want to put some sort of error reporting here. Even logging the error to a text file is fine.
          echo 'There was a problem saving your score. Please try again later.';
         
     }
     
}else{
     echo 'Your name or score wasnt passed in the request. Make sure you add ?name=NAME_HERE&score=1337 to the tags.';
}
 
$dblink->close;//Close off the MySQL connection to save resources.
?>