Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL Fatal Error #2

Open
connorhsm opened this issue Mar 24, 2022 · 3 comments
Open

MySQL Fatal Error #2

connorhsm opened this issue Mar 24, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@connorhsm
Copy link
Member

Fitness Server causing fatal error:

Fatal error: Database query failed:
SELECT life_id, life_player_id, name, age, display_id, relation_name, offspring.score_change, offspring.death_time, TIMESTAMPDIFF( SECOND, offspring.death_time, CURRENT_TIMESTAMP ) as died_sec_ago FROM fitnessServer_offspring AS offspring INNER JOIN fitnessServer_lives AS lives ON offspring.life_id = lives.id WHERE offspring.player_id = AND offspring.death_time > DATE_SUB( NOW(), INTERVAL 168 HOUR ) ORDER BY offspring.death_time DESC LIMIT 20;

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND offspring.death_time > DATE_SUB( NOW(), INTERVAL 168 HOUR ) ORDER BY offspri' at line 1

Suspected code/query causing issues:

$query = "SELECT life_id, life_player_id, name, age, display_id, relation_name, ".
"offspring.score_change, offspring.death_time, ".
"TIMESTAMPDIFF( SECOND, offspring.death_time, CURRENT_TIMESTAMP ) as died_sec_ago ".
"FROM $tableNamePrefix"."offspring AS offspring ".
"INNER JOIN $tableNamePrefix"."lives AS lives ".
"ON offspring.life_id = lives.id ".
"WHERE offspring.player_id = $id ".
"AND offspring.death_time > DATE_SUB( NOW(), INTERVAL $scoreRollingWindow HOUR ) ".
"ORDER BY offspring.death_time DESC ".
"LIMIT $maxOffspringToShowPlayer;";

@connorhsm
Copy link
Member Author

@risvh I'm having some trouble figuring what causes this error.
I believe the query I've found in server.php is executed when displaying the Genes page on the client, but can't reproduce the error myself.
I also can't spot any immediate errors in the query, apart from some formatting differences in the PHP.

Are you able to offer any help here?

@connorhsm
Copy link
Member Author

Although
...WHERE offspring.player_id = ?? AND offspring.death_time >...
It looks as if there might be a missing ID in the query, where I have added the ??.

@risvh
Copy link
Contributor

risvh commented Mar 24, 2022

Yes there should be an ID there "WHERE offspring.player_id = $id ".
and further above $id = fs_mysqli_result( $result, 0, "player_id" );
which in turn comes from the offspring table

$query = "SELECT email, player_id, round(sum(score_change), 4) as score, max(death_time) as last_death_time ".
"FROM $tableNamePrefix"."offspring as offspring ".
"INNER JOIN $tableNamePrefix"."users as users ".
"ON offspring.player_id = users.id ".
"WHERE death_time > DATE_SUB( NOW(), INTERVAL $scoreRollingWindow HOUR ) ".
"AND email = '$email' ".
"GROUP BY player_id ".
"ORDER BY score DESC, last_death_time DESC;";
$result = fs_queryDatabase( $query );
$score = fs_mysqli_result( $result, 0, "score" );
$id = fs_mysqli_result( $result, 0, "player_id" );

@connorhsm connorhsm added the bug Something isn't working label Apr 9, 2023
@connorhsm connorhsm moved this to Todo in General dev tasks Apr 9, 2023
@connorhsm connorhsm moved this from Todo to In Progress in General dev tasks Apr 9, 2023
@connorhsm connorhsm self-assigned this Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In Progress
Development

No branches or pull requests

2 participants