So I’m writing a PHP class called article and it has a bunch of methods like insert, delete and update. I have 3 other functions that follow the same code and they all work so I don’t know why I am getting this error. Here is the code I wrote.
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);
}
}
I read that you can get it from previous queries so I tried renaming and setting a bunch of the variables to null. I also checked the other threads I could find from this site and other and almost all of them were scope issues, which I don’t think is the problem here since all my other functions work. Is there something painfully obvious that I’m missing?
It should be
$connection1->prepare(), not$statement->prepare().