-1

所以我正在编写一个名为 article 的 PHP 类,它有很多方法,如插入、删除和更新。我有 3 个其他函数遵循相同的代码,它们都可以工作,所以我不知道为什么会出现这个错误。这是我写的代码。

public function update(){

    //make sure that the article does have an I.D
    if(is_null($this->id)) trigger_error("Article::update(): Attempt to update an Article object that does not have its ID property set.", E_USER_ERROR );

    //If there are any PDO errors they will be caught.
    try{
        $connection1 = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
        $connection1->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
        $sqlQuery = "UPDATE articles SET lastEditDate=FROM_UNIXTIME(:lastEditDate), lastEditUser=:lastEditUser, title=:title, content=:content WHERE id = :id";
        $statement->prepare($sqlQuery);
        $statement->bindValue(":lastEditDate", $this->lastEditDate, PDO::PARAM_INT);
        $statement->bindValue(":lastEditUser", $this->lastEditUser, PDO::PARAM_STR);
        $statement->bindValue(":title", $this->title, PDO::PARAM_STR);
        $statement->bindValue(":content", $this->content, PDO::PARAM_STR);
        $statement->bindValue(":id", $this->id, PDO::PARAM_INT);
        $statement->execute();
        $connection1 = null;

    }


    catch(PDOException $e){
        echo "update():I'm sorry, Dave. I'm afraid I can't do that.";  
        file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
    }


}

我读到你可以从以前的查询中得到它,所以我尝试重命名并将一堆变量设置为空。我还检查了我可以从该站点和其他站点找到的其他线程,几乎所有这些线程都是范围问题,我认为这不是问题,因为我的所有其他功能都可以工作。有什么明显的痛苦我想念的吗?

4

1 回答 1

2

应该是$connection1->prepare(),不是$statement->prepare()

于 2012-06-18T21:38:18.967 回答