> The code shown here https://www.w3schools.com/php/func_mysqli_connect.asp is relatively correct at the moment. Maybe not nice, but it handles the error. That is the second hit on google (after php.net manual) when searching for "php tutorial mysqli_conect") Most other books, tutorials, ... teach the same.
w3schools is hardly something that should be regarded as a reputable source of information and should not impact the direction PHP is heading in. This problem comes mostly from the fact that the developers who wrote these tutorials were unaware that there is automatic error reporting available. PHP manual didn't explain this either. This RFC proposes to change that by making it the default so that people can't miss it. The reason why I really want this default setting to change is that I was lied to by books and tutorials when I was learning PHP. I wish I knew about automatic error reporting instead of struggling with invisible SQL errors. I still hold a grudge against the tutorials teaching me manual error checking or the use of real_escape_string. I do not want new developers in the era of PHP 8 to suffer the same pain I did. > Spend a day looking at stackoverflow and you see a different world. Also many users just want to use a PHP app and don't care about PHP. Yes, but once again the problem is the old tutorials that teach it incorrectly. Most of them still are vulnerable to SQL injection. We can't change the tutorials but we can change the recommended setting in PHP. > In 8.1 add deprecation notices to mysqli_connect & friends AND to access to the connection_error (if I remember right that goes via the __get hook, thus we can add a deprecation note to a "property" access) > The later is a good place as many people use the @ operator on the connect, but not on the error check. > In a later version we change it. > That gives a chance to reach users. We will still miss many, but for a notable amount of people there is a chance. I believe Nikita has proposed it already. I am not very happy about it as this would mostly go unnoticed. People who have mysqli error reporting silenced often have every other error reporting silenced too including deprecation notices. Adding such deprecation notice would just create another confusing PHP error that developers would have to fix. I am sorry to say this about my fellow developers but many of the ones that you are targeting with this proposal who wouldn't read an upgrade guide before upgrading, are also the ones who would ignore this deprecation warning in their error logs. "Hey, the code still works, I don't know what this deprecation notice is talking about!" For these reasons, I am unwilling to go through a deprecation phase. I believe it would be just a waste of time. But if this is the only way that this change will land in PHP then I would also accept it as a very unsatisfying compromise. >