Why is PDO better for escaping MySQL queries/querystrings than mysql_real_escape_string?

As the current answers go into details while your question is more aimed at a general overview, I’ll give it a try: The PDO classes aim to encapsulate all the functionality needed to interact with a database. They do this by defining ‘methods’ (OO parlor for functions) and ‘properties’ (OO parlor for variables). You’d use … Read more

mysql_escape_string VS mysql_real_escape_string

The difference is that mysql_escape_string just treats the string as raw bytes, and adds escaping where it believes it’s appropriate. mysql_real_escape_string, on the other hand, uses the information about the character set used for the MySQL connection. This means the string is escaped while treating multi-byte characters properly; i.e., it won’t insert escaping characters in … Read more

Alternative to mysql_real_escape_string without connecting to DB

It is impossible to safely escape a string without a DB connection. mysql_real_escape_string() and prepared statements need a connection to the database so that they can escape the string using the appropriate character set – otherwise SQL injection attacks are still possible using multi-byte characters. If you are only testing, then you may as well … Read more

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