Set (Update) Field in Database

Greetings everyone, i had a trouble while updating the query.
I tried to update an existing table using this query, but got an error. Here’s my code:

    $qb = $this->db->getQueryBuilder();

            $qb->update($this->getTableName())
                    ->set('h_condition', $health_condition)
                    ->where(
                    $qb->expr()->eq('employee_id', $qb->createNamedParameter($employee_id))
            );
            $qb->execute();

Note:
$employee_id = 49 and $health_condition = “Healthy”
In DB; employee_id is PK, int & auto-increment, h_condition is varchar.

The error message is:

Doctrine\DBAL\Exception\InvalidFieldNameException: An exception occurred while executing ‘UPDATE oc_employee SET h_condition = Healthy WHERE employee_id = ?’ with params [49]: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘Healthy’ in ‘field list’

Could you help to shed some light? Thanks in advance.

Best Regards,
Travis

1 Like
    $qb = $this->db->getQueryBuilder();

            $qb->update($this->getTableName())
                    ->set('h_condition', $qb->createNamedParameter($health_condition))
                    ->where(
                    $qb->expr()->eq('employee_id', $qb->createNamedParameter($employee_id))
            );
            $qb->execute();
2 Likes

Thanks good sir! It finally worked!
Once again, thank you for your help. I really appreciate it.

1 Like