Can’t successfully check if post with title exist in database

You have typing mistake. You are using the double quotation mark instead of single quotation mark at the end of the code post_status = "publish"

Please use post_status="publish" instead of post_status="publish" and then use double quotation mark at the end of query.

And also make sure that dynamic values are correctly entered in the query by printing the query before execution.