On the Internet, I found only one way to crack the Mysql database - sql-injection. However, in the same place I found a solution how to prevent unwanted characters from entering mysql_query
:
$query = sprintf("SELECT * FROM sometable WHERE somevar='%s'", mysql_real_escape_string($var)); mysql_query($query);
Nevertheless, many people strongly recommend switching to other extensions for working with Mysql (PDO, for example), considering the original API to be a priori unsafe and not sufficiently functional. I'm not complaining about the latter, but safety is important to me.
And here is the question: Has the code given above completely protected me from hacker attacks? If not, is it possible for me to be fully secure without going over to other extensions?
mysql
extension for php was officially declared obsolete a few years ago ( php.net/manual/ru/function.mysql-query.php right in the red box above it is written). If I'm not mistaken, in current versions of PHP 7. * it is already missing. So it's not just that "people say." But it is not necessary to switch to PDO, you can simply use mysqli in the same way. - Ivan Pshenitsyn