0
\$\begingroup\$

I want to store the updated score in mysql database. So, what i do for that?

private void updateScore() {
    if (winner.equalsIgnoreCase("You")) {
        tally = 100 - computer.getId();
        MainActivity.userScore += tally;
        if (MainActivity.userScore >= MainActivity.maxEnd) {
            MainActivity.   stat++;
            MainActivity.totTurn++;
            MainActivity.userScore = 0;
            MainActivity.computerScore = 0;

        }

    }
    if (winner.equalsIgnoreCase("computer")) {
        tally = 100 - buddy.getId();
        MainActivity.computerScore += tally;
        if (MainActivity.computerScore >= MainActivity.maxEnd) {

            MainActivity.totTurn++;
            MainActivity.userScore = 0;
            MainActivity.computerScore = 0;
        }
    }
    MainActivity.saveConfig();
}
\$\endgroup\$
2
  • \$\begingroup\$ I assume that mySQL database runs on a server on the internet? \$\endgroup\$
    – Philipp
    Dec 1, 2017 at 12:13
  • \$\begingroup\$ Mysql database runs through xampp server. and i want to store the updated score in php mysql database. \$\endgroup\$
    – user109752
    Dec 1, 2017 at 12:13

1 Answer 1

2
\$\begingroup\$

You don't. Accessing an online MySQL database from a client application directly is a really bad idea for security reasons. The permission handling abilities of MySQL aren't refined enough to check what a game client can and can not write to and read from the database. You also can not restrict access to only your game client, because the MySQL server can not detect what software is behind an incoming connection (actually no server application can do that).

What you should do instead is create a server application using your preferred server application development technology. That server receives requests from the Android clients, verifies that they contain something the client is allowed to do, formulates and sends a query to the MySQL database and returns the results to the clients. Your MySQL database should be configured to only process queries which come from that server application.

Each of these steps allows a lot of creative freedom in implementation details, so giving a complete walkthrough would go too far here. If you have specific questions about them, please ask in form of a new question.

\$\endgroup\$

You must log in to answer this question.