Is your feature request related to a problem?
Yes! I spent all damn afternoon trying to diagnose why upgrading a host from PHP 5.4 to PHP 7 borked Textpattern. After flicking PHP version, all I got back was "Database unavailable."
The reason? The database user account was so old (like, almost 15 years old) that it was created with an ancient hashing algorithm that PHP 7+ rejects. So when it tries to do a mysqli_real_connect() and passes the old user account credentials, the database attempts to match the mysql.user stored with the ancient algorithm. PHP throws a fit, the connection isn't made and the database 'isn't available'.
Since it's a shared hosting environment, I didn't have the luxury of editing the mysql.user table to tell it to accept old native passwords, nor could I edit my.cnf likewise.
The solution? From cpanel, edit the database user for the connection and change its password to exactly the same password as it is now. That forces MySQL to regenerate the hash for the database user via a modern algorithm, so PHP 7 is happy, and PHP 5 continues to work using the existing password (as it hasn't changed).
What is the feature?
When the connection fails in some way, display 'Database unavailable' as usual but then underneath that, add the mysql error message returned in $this->link. Primarily any of these array keys that aren't empty:
connect_errno
connect_error
errno
error
Had this been available, the returned message: "The server requested authentication method unknown to the client" might have been more of a clue what was going on.
We may like to extend this idea to other areas of core as and when we gradually phase out use of @ to hide errors, and use try/catch instead for better exception handling.
Is your feature request related to a problem?
Yes! I spent all damn afternoon trying to diagnose why upgrading a host from PHP 5.4 to PHP 7 borked Textpattern. After flicking PHP version, all I got back was "Database unavailable."
The reason? The database user account was so old (like, almost 15 years old) that it was created with an ancient hashing algorithm that PHP 7+ rejects. So when it tries to do a
mysqli_real_connect()and passes the old user account credentials, the database attempts to match the mysql.user stored with the ancient algorithm. PHP throws a fit, the connection isn't made and the database 'isn't available'.Since it's a shared hosting environment, I didn't have the luxury of editing the mysql.user table to tell it to accept old native passwords, nor could I edit my.cnf likewise.
The solution? From cpanel, edit the database user for the connection and change its password to exactly the same password as it is now. That forces MySQL to regenerate the hash for the database user via a modern algorithm, so PHP 7 is happy, and PHP 5 continues to work using the existing password (as it hasn't changed).
What is the feature?
When the connection fails in some way, display 'Database unavailable' as usual but then underneath that, add the mysql error message returned in
$this->link. Primarily any of these array keys that aren't empty:connect_errnoconnect_errorerrnoerrorHad this been available, the returned message: "The server requested authentication method unknown to the client" might have been more of a clue what was going on.
We may like to extend this idea to other areas of core as and when we gradually phase out use of
@to hide errors, and use try/catch instead for better exception handling.