Fatal error: Call to a member function table() on a non-obje

2016-07-07 15:02 来源:www.chinab4c.com 作者:ecshop专家

我想在一个新建的文件中获得购物车的信息,我直接复制了lib_insert.php中的这段代码:
  1. $sql = 'SELECT SUM(goods_number) AS number, SUM(goods_price * goods_number) AS amount' .
  2. ' FROM ' . $GLOBALS['ecs']->table('cart') .
  3. " WHERE session_id = '" . SESS_ID . "' AND rec_type = '" . CART_GENERAL_GOODS . "'";
  4. $row = $GLOBALS['db']->GetRow($sql);

  5. if ($row)
  6. {
  7. $number = intval($row['number']);
  8. $amount = floatval($row['amount']);
  9. }
  10. else
  11. {
  12. $number = 0;
  13. $amount = 0;
  14. }
复制代码



但运行出错,Fatal error: Call to a member function table() on a non-object in……,请问下是怎么回事,谢谢

回答:
是不是库文件被删除或者修改过

你新建的文件,得在头部加一段包含代码
  1. define('IN_ECS', true);

  2. require(dirname(__FILE__) . '/includes/init.php');
复制代码

楼上正解,可能就是新文件没有引入init.php文件




嗯,谢谢,已经搞定了!