I am not sure why but I am getting this error
Fatal error: Call to a member function update() on a non-object in /home/XXXXXXXXXXXXXXXXX/classes/core.php on line 22
On that page I have this
public function updatemongo($from,$data)
{
$this->db = $m->exchange_rates;
$collection = $this->db->exchangeDB;
$collection->update(array("from" => $from), $data);
}
this is how I am calling this function
foreach ($currencies as $to)
{
if($from != $to)
{
$url = 'http://finance.yahoo.com/d/quotes.csv?f=l1d1t1&s='.$from.$to.'=X';
$handle = fopen($url, 'r');
if ($handle) {
$result = fgetcsv($handle);
fclose($handle);
}
$newdata = array('$set' => array("exchangehistory.{$result[1]}.{$result[2]}" => array("to" => $to, "rate" => $result[0], "updated" => $result[2])));
$fetch->updatemongo($from,$newdata);
$newdata = array('$set' => array("currentexchange" => array("to" => $to, "rate" => $result[0], "updated" => $result[2])));
$fetch->updatemongo($from,$newdata);
}
}
and yes the file needing to access this is also has require_once("core.php");
Please let me know why this is not working.
The
updatemongo()function doesn’t have access to the$mvariable. Please pass it to the function like this:And change your function definition to:
public function updatemongo($m, $from, $data)
{
Alternatively, you can set the
mproperty of the object to the connection after you’ve created it. For example with:Or perhaps you can just use
$this->exchange_ratesalready above… in any case, you’re not making$mavailable to the function.