We need to use `$db->exec($query);` instead of `$db->query($query);`. It returns the number of affected rows.