Skip to content

onDuplicate problem when there was no change in data #375

@Ettemlevest

Description

@Ettemlevest

I'm using an insert statement with onDuplicate. If a user saves a data without anyy changes (record already in the database) the insert returns with bool(false) error. But there is no database error just 0 affected rows with the execution of the query.

Used code:

$data = [
    'id' => $id,
    'data_1' => $data_1,
    'data_2' => $data_2,
];

$db->onDuplicate(['data_1', 'data_2']);
if (!$db->insert('megbizasok_kamionok', $data))
    throw new DBException('json');

My problem is in the _buildInsert() function:

if ($stmt->affected_rows < 1) {
    return false;
}

Why is this considered an error when sql error number is 0?
Should I use a different approach?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions