致命错误:在没有pdo包装类的对象上下文中时使用$ this

时间:2012-08-24 07:43:22

标签: php mysql pdo

我在我的php应用程序中使用simpleSQL - PDO类,
并使用此代码:

$where['username']=$_POST['username'];
$where['password']=md5($_POST['password']);

$DB = new DB();
$res=$DB->buildQuery('tbl_admin',$where);

它在localhost中正常工作,但在在线服务器上它会收到错误:

Fatal error: Using $this when not in object context in DB.php on line 230  

行号DB类中的230是:

$ item  = $ this- > instance- > quote ($ this- > escape ($ item)); 

我的问题在哪里?

1 个答案:

答案 0 :(得分:2)

这是班上的一个错误。

buildQuery方法中:

array_walk($where,'DB::prepareDbValues'); 

这会静态调用prepareDbValues方法(因此,不在对象上下文中 - > $this未定义)。要解决此问题,请将其替换为

array_walk($where,array($this, 'prepareDbValues')); 

并向班级作者报告错误和修复。