sareea Posted August 26, 2011 Share Posted August 26, 2011 Hello, I am trying to run a script on my site , The script is this : https://github.com/simplecoin/simplecoin and I am getting these errors [sat Aug 13 11:47:01 2011] [error] [client 84.228.254.88 ] PHP Fatal error: Call to a member function fetch() on a non-object in /var/www/includes/stats.php on line 42,[/code] ] PHP Warning: Invalid argument supplied for foreach() in /var/www/includes/stats.php on line 89 and ] PHP Warning: Invalid argument supplied for foreach() in /var/www/stats.php on line 75 I run ubuntu 11 vps . Some one told me that [quote]Probably this query is not returning a value, so it gives an error. [code]$sql = "SELECT count(id) FROM shares WHERE id > $lastwinningshare AND our_result='N'"; Most likely it will go away as soon as it returns something. from the file /includes/stats.php I really need to fix this problem , is there any module i need to install or the code is incorrect ? If you want i can give you a link to php info of my vps . Thanks a lot for the help ! Quote Link to comment https://forums.phpfreaks.com/topic/245745-php-fatal-error/ Share on other sites More sharing options...
Muddy_Funster Posted August 26, 2011 Share Posted August 26, 2011 any chance of posting your acctual code? Quote Link to comment https://forums.phpfreaks.com/topic/245745-php-fatal-error/#findComment-1262189 Share on other sites More sharing options...
sareea Posted August 26, 2011 Author Share Posted August 26, 2011 Yes function currentstales() { global $read_only_db; $currentshares = 0; $lastwinningshare = $this->lastWinningShareId(); if (!($currentshares = getCache("pool_stales"))) { $sql = "SELECT count(id) FROM shares WHERE id > $lastwinningshare AND our_result='N'"; $result = $read_only_db->query($sql); if ($row = $result->fetch()) { $currentshares = $row[0]; setCache("pool_stales", $currentshares, 300); } } return $currentshares; } From this file : https://github.com/simplecoin/simplecoin/blob/master/includes/stats.php Thanks ! Edit: and this is my php info http://wemine.co.in/testphp.php Quote Link to comment https://forums.phpfreaks.com/topic/245745-php-fatal-error/#findComment-1262193 Share on other sites More sharing options...
Muddy_Funster Posted August 26, 2011 Share Posted August 26, 2011 Try: function currentstales() { global $read_only_db; $currentshares = 0; $lastwinningshare = $this->lastWinningShareId(); if (!($currentshares = getCache("pool_stales"))) { $sql = "SELECT count(id) FROM shares WHERE id > $lastwinningshare AND our_result='N'"; $result = $read_only_db->query($sql); if ($row = $result->fetch(PDO::FETCH_ASSOC)) { $currentshares = $row[0]; setCache("pool_stales", $currentshares, 300); } } return $currentshares; } Quote Link to comment https://forums.phpfreaks.com/topic/245745-php-fatal-error/#findComment-1262214 Share on other sites More sharing options...
sareea Posted August 26, 2011 Author Share Posted August 26, 2011 Hello, Now it calls the error to be in this function ... function usersharecount($userId) { global $read_only_db; $totalUserShares = 0; $workers = Array(); $lastwinningshare = $this->lastWinningShareId(); if (!($totalUserShares = getCache("user_shares_".$userId))) { $workers = $this->workers($userId); $sql = "SELECT count(id) as id FROM shares WHERE id > $lastwinningshare AND username in ('".implode("','",$workers)."')"; $currentSharesQ = $read_only_db->query($sql); if ($currentSharesR = $currentSharesQ->fetch()) { $totalUserShares = $currentSharesR[0]; setCache("user_shares_".$userId, $totalUserShares,3); } } return $totalUserShares; } If i enter my site wemine.co.in , it enters, after i try to login it returns this error ... Warning: array_key_exists() expects parameter 2 to be array, boolean given in /var/www/includes/stats.php on line 239 Fatal error: Call to a member function fetch() on a non-object in /var/www/includes/stats.php on line 276 Thanks for the help ! Quote Link to comment https://forums.phpfreaks.com/topic/245745-php-fatal-error/#findComment-1262219 Share on other sites More sharing options...
Muddy_Funster Posted August 26, 2011 Share Posted August 26, 2011 You'll likely need to include PDO::FETCH_ASSOC within all your fetch() for it to work properly. see here: http://php.net/manual/en/pdostatement.fetch.php Quote Link to comment https://forums.phpfreaks.com/topic/245745-php-fatal-error/#findComment-1262253 Share on other sites More sharing options...
sareea Posted August 26, 2011 Author Share Posted August 26, 2011 Hello, i tried it and it still doesn't work, do you think that i have a missing module in my server ? here is my info wemine.co.in/testphp.php Thanks a lot ! Quote Link to comment https://forums.phpfreaks.com/topic/245745-php-fatal-error/#findComment-1262410 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.