-2

I am working on web app for treasure hunt all connection to the online server is correct and the application is working fine and save and get the data from / to online mysql database.

on my application I register a session for (start time) and session for (end time) where the (end time) means that the user has finished the game.

I am getting the winner number from this (end time) and organize the winners based on there (end time)

the problem is that on localhost (using XAMPP) I get the winner number correctly. while if I upload my work to my hosting (Linux with CPanel) I always get the winner as 0 (even if it wasn't the first)

This is the result that I get online

this is the result that I get online

while if I am on localhost I get the winner number correctly

localhost I get the winner number correctly

this is the code to get the winner:

function getWinner($uid, $set){

    $db = new Db();
    $winner = 0;
    $query = "SELECT endtime FROM eid_race WHERE id = '$uid' AND endtime IS NOT NULL";
    $result = $db->query($query);
    if(sizeof($result) == 0){
        $updateEndtime = "UPDATE eid_race SET endtime = UNIX_TIMESTAMP() WHERE id = '$uid'";
        $db->execute($updateEndtime);
    }
        $query = "SELECT COUNT(id) FROM eid_race WHERE id <> '$uid' AND endtime IS NOT NULL AND endtime < (SELECT endtime FROM eid_race WHERE id = '$uid') AND questionset = '$set'";
    $result = $db->query($query);
    echo '  result:  ' . $result[0][0];
    if(sizeof($result) == 1){
        $winner = $result[0][0];
        echo '  winner:  '.$winner;
    }

    echo '  winner after:  '.$winner;


    return $winner+1;

}

when I test the query directly on phpmyadmin I get correct result but the php result still 0

SELECT COUNT(id) FROM eid_race WHERE id <> '577dd5759fa67' AND endtime IS NOT NULL AND endtime < (SELECT endtime FROM eid_race WHERE id = '577dd5759fa67') AND questionset = 'A'

enter image description here

7
  • 1
    Put a test file with phpinfo() on server and compare the PHP/Mysql versions. Commented Jul 7, 2016 at 4:39
  • 2
    @SumanSingh is right and since you are dealing with datetime and timestamp in mysql then you should check the server timezone and date time settings. Commented Jul 7, 2016 at 4:50
  • @SumanSingh localhost: PHP Version 5.6.15 , mysql Client API version mysqlnd 5.0.11-dev , Online Server: PHP Version 5.3.29, mysql Client API version 5.6.30 -- Commented Jul 7, 2016 at 4:55
  • @AvishekChat how can I prevent the changes between online timezone and localhost. localhost timezone: Europe/Berlin , **Online Server Timezone: ** UTC Commented Jul 7, 2016 at 5:00
  • Run "SELECT COUNT(id)...." query directly into phpmyadmin.. Commented Jul 7, 2016 at 5:04

1 Answer 1

0

You can modify the timezone of mysql on my.ini file in windows and my.cnf file in linux and mac system. But I think the best solution is to change the timezone from query using

 set time_zone = '+2:00';   --Timezone:Europe/Berlin

and check the current datetime using select now();

Sign up to request clarification or add additional context in comments.

5 Comments

my localhost time_zone is '+2:00' (Europe/Berlin), Online is UTC
checking SELECT now() *localhost: * 2016-07-07 08:43:12, **Online: ** 2016-07-07 13:43:49
Ok, then run the query set time_zone = '+2:00'; on the server and check.
still nothing changed, I tried to set variable $end_time = time() on php and assigned it to endtime column instead of UNIX_TIMESTAMP() . still nothing changed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.