HTML Entities in Post Title

It seems like the crux of the question is this:

This causes the first ‘if’ condition to return TRUE and it inserts a
duplicate post.

Check for the post_name instead. That value is normalized to lowercase and dashes by sanitize_title_with_dashes so you won’t have this issue. That value is also the one that WordPress enforces as unique, and the one used as a permalink.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)