PHP fatal error

Hello,
I am trying to run a script on my site ,

The script is this :


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

[code]] 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

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'";[/code] 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 !

Amazing how many people make this error. Here is the problem, second in two days:
$sql = “SELECT count(id) FROM shares WHERE id > $lastwinningshare AND our_result=‘N’”;
That is a string, so when it is called, it is treated like a string and not an action. Instead, you need to let PHP know it is an action with mysql_query().
$sql = mysql_query(“SELECT count(id) FROM shares WHERE id > $lastwinningshare AND our_result=‘N’”);
I would test it again as I don’t know much about queries yet and so I still don’t see any other error than that. Anyhow if that was the only error with your code it should work now.

Hello,
This is the code that is returning the error,

[php]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;
}[/php]

I tried to add the mysql_query and it didn’t work. And i also see
$currentSharesQ = $read_only_db->query($sql);

Should this be changed after the changes i made to the $sql ?
thanks a lot ! :slight_smile:

You are using MYSQL? Not SQLite? Then try:
$currentSharesQ = $read_only_db->mysql_query($sql);
Did you also:
Connect to host? mysql_connect(“myhostname”,“username”,“password”);
Select the database? mysql_select_db(“readonlydb”);
And where is the foreach that causes the error?

Hello !
Thanks for the help,
some one from another forum found a solution …
and he said this :

it was because there was no $lastwinningshare I manually set it to 1 now everything is good

What is this ? How can i make what he said .

And this is the file that has the code , i think it includes the call for the mysql database …
https://github.com/simplecoin/simplecoin/blob/master/includes/stats.php

Sponsor our Newsletter | Privacy Policy | Terms of Service