3

I have a legacy PHP forum that I'd like to make available read-only for archive purposes. I've managed to get it running in a docker container using php 5.4, and I have it connecting just fine to a MySQL 5 container.

When I switch to using MySQL 8, it fails to connect for two reasons:

  1. MySQL 8 switched the default authentication protocol from mysql_native_password to caching_sha2_password, and php's mysql driver does not support the latter protocol. I fixed this by creating a user that uses the mysql_native_password authentication mechanism.

  2. MySQL 8 switched the default server's character set from utf8 to utf8mb4, which php's mysql driver does not support. It's this issue that has me stuck.

The PHP error is:

Warning: mysql_connect(): Server sent charset (255) unknown to the client.

I know I can fix it by changing the MySQL server's character set, but I'm running this in a Managed MySQL cluster in production (from Digital Ocean), and I don't have access to change that. So I'm wondering if I can change it on a database level, or client/connection level.

I've tried changing the database's encoding before importing the data using:

ALTER DATABASE
    database_name
    CHARACTER SET = utf8
    COLLATE = utf8_unicode_ci;

I've also tried changing the connection charset in PHP using:

$this->db_connect_id = mysql_connect($this->server, $this->user, $this->password);
mysql_set_charset("UTF8", $this->db_connect_id);

But the "Server sent charset unknown" error is on the mysql_connect line, so by the time mysql_set_charset runs, the error has already been thrown, and db_connect_id is false.

I also know that I could upgrade PHP and switch from the legacy mysql extension to mysqli or PDO, but this forum is from 2005, and I never intend to use it; it's just for archival purposes. I'm hoping it's possible to just get it working without having to upgrade it.

Any suggestions?

yivi
  • 42,438
  • 18
  • 116
  • 138
Tobias Fünke
  • 2,034
  • 3
  • 24
  • 38
  • 2
    PHP 5.4 is out of support since years... you should upgrade it not only for better performance, but also for all the security related bug fixes – Nico Haase Apr 13 '21 at 06:48
  • Thanks Nico, but the only way to circumvent this issue is to upgrade to PHP 7, which does not support the mysql extension (only mysqli or PDO). This would require me to dive into the depths of the phpbb and smf forum codebases. I don't need good performance, or security fixes, as I plan to make this read-only. – Tobias Fünke Apr 13 '21 at 06:50
  • 2
    Then stay on MySQL 5 if you don't want to run upgrades ;) – Nico Haase Apr 13 '21 at 06:57
  • Just a note: If you don't want to upgrade PHP to a supported and secure version, I really hope you're not accepting users to sign up. If you do, you are knowingly putting their credentials at risk (since people tend to reuse credentials) since you know it's an old and unsupported PHP version.. – M. Eriksson Apr 13 '21 at 07:05
  • 1
    The OP mentioned "read only for archive purposes" on the first line. So they are not encouraging anyone to sign-up. – yivi Apr 13 '21 at 07:06
  • 2
    Even existing accounts could be at risk so let's hope they wipe all sensitive user data as well. – M. Eriksson Apr 13 '21 at 07:07

1 Answers1

-1

I just downgraded my php to 5 in order to make it work on Centos 8. The newer php already was not working. Now everything works, with 1 javascript edit, accept for the mysql connection.

Susie
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 12 '23 at 23:25