I'm trying to understand whether mysql_real_escape_string($str) can be empty if $str is not empty (by $str is empty I mean that empty($str) is true)?
1 Answer
mysql_real_escape_stringReturns the escaped string, or
FALSEon error.
So the return value is either false if there's an error (like not being connected to the database), which counts as "empty". Or it's the escaped string, which means that there are additional escape characters in the string. mysql_real_escape_string will not reduce the string.
So if the string has content and you are connected to the database, if the input is not "empty", the output won't be either. If there's an error though, the output will be "empty".
mysql_real_escape_stringwill be empty if you are not connected to a database.mysql_*functions in new code. They were removed from PHP 7.0.0 in 2015. Instead, use prepared statements via PDO or MySQLi. See Why shouldn't I use mysql_* functions in PHP? for more information.FALSEof boolean typeFALSEwould be converted to a string.echo FALSEwill echo nothing.empty()function, i.e.== false, then both an "empty string" andfalseare "empty".