In my application I’m using SQLite3, and right now I’m trying to get DELETE to work. The code below seems fine for me, and I’ve checked that $producerId holds the Id, which of course exists in the database.
However, I get false back as a result from the query execution, and the posts doesn’t get deleted.
What am I doing wrong?
public function deleteProducer($producerId) {
$sql = "DELETE FROM 'producers' WHERE 'producerid' = $producerId";
$result = $this->m_db->exec($sql);
return $result; // <- 0 (fails)
}
database structure:
Table: producers
Fields: id(INTEGER PRIMARY KEY), producerid(INT), name(TEXT), address(TEXT), zipcode(INT), town(TEXT), url(TEXT), imgurl(TEXT)
In SQL, single quotes are used for strings.
SQLite will accept a string instead of an identifer when the meaning is clear from the context (such as for the table name), but in the
WHEREcondition, strings are allowed, so'producerid'will be interpreted as string.For identifiers, use double quotes: