0

I have a problem with my SQL statement written in PHP.

I am using store() function to both INSERT or UPDATE object in the database following it's rule that it can be done:

The INSERT OR UPDATE command is an extension of the INSERT command, with these differences: If the row being inserted does not exist, INSERT OR UPDATE performs an INSERT operation. If the row being inserted already exists, INSERT OR UPDATE performs an UPDATE operation, updating the row with the specified column values.

I wrote type declaration for the Content ID like : public ?$contentId = null; so I can use the same methods for both actions.

public function store(Content $content, int $teamId)
{
    $rsm = new ResultSetMapping($this->entityServiceRepository);
    $stmt = $this->entityServiceRepository->getConnection()->prepare(
        'UPDATE content
        SET
            name = :name,
            url = :url,
            WHERE id = :contentId
            AND team_id = :teamId
            ',
        $rsm
    );

    $stmt->bindValue("contentId", $content->getId(), PDO::PARAM_INT);
    $stmt->bindValue("teamId", $content, PDO::PARAM_INT);
    $stmt->bindValue("name", $content->getName(), PDO::PARAM_STR);
    $stmt->bindValue("url", $content->getUrl(), PDO::PARAM_STR);

    $stmt->executeQuery();

However from some reason data does not exist in the database. All bindValue() return true ant other sql queries seems to work well. How can I debug this query? Or can someone tell is there a problem with sql query I wrote.

Thanks.

0 Answers0