PHP Mongodb not updating array -
i not sure why getting error
fatal error: call member function update() on non-object in /home/xxxxxxxxxxxxxxxxx/classes/core.php on line 22 on page have this
public function updatemongo($from,$data) { $this->db = $m->exchange_rates; $collection = $this->db->exchangedb; $collection->update(array("from" => $from), $data); } this how calling function
foreach ($currencies $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 file needing access has require_once("core.php");
please let me know why not working.
the updatemongo() function doesn't have access $m variable. please pass function this:
$fetch->updatemongo($m, $from, $newdata); and change function definition to:
public function updatemongo($m, $from, $data) {
alternatively, can set m property of object connection after you've created it. example with:
public function __construct) { $this->m = new mongo(); } ... public function updatemongo($from, $data) { $this->db = $this->m->exchange_rates; $collection = $this->db->exchangedb; $collection->update(array("from" => $from), $data); } or perhaps can use $this->exchange_rates above... in case, you're not making $m available function.
Comments
Post a Comment