开发者

Fatal error: Call to a member function execute() on a non-object...PDO

I have PHP 5.2.3, apache2.x, MySQL 5.x on a Linux machine. Everything was working fine until yest开发者_运维知识库erday. This morning all of a sudden one of the PHP files started to throw "Fatal error: Call to a member function execute() on a non-object in". I use PDO (prepare, execute, close cursor etc). Have you ever come across this problem? does someone know a fix for this, please?

Many thanks, R


Your prepare call is probably failing. This is probably due to a SQL statement that is not valid.

We would need to know exactly what library you are using to know more, but prepare is probably returning false instead of an object. Then when you try to call execute on the return value, you are trying to call it on false instead of an object, causing the error message you see.

If you echo or var_dump the value you are calling execute on, you will be able to see more details.


As Alan says, the problem is probably that prepare is returning false rather than a PDOStatement. The best way to debug this is to turn warnings on. To do this, put this code right after you initialise PDO:

$db = new PDO();  // insert the following after this line
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );

This will mean that a PHP warning will be raised by PDO when the prepare statement fails. This should contain information that will help you debug the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜