No more database port number problems?
-
Dear MailPoet team,
I have seen various port number problems with MailPoet causing the plugin not to work; for example on Local (Flywheel, WP Engine) as web server and when using MariaDB on a Synology NAS.
On Local the problem is not only that you have to specify the right port number in wp-config.php; you will also have to think about this when transferring your site to a different platform. Really unpleasant.
After looking into this further, I think that there may be a simple solution for you to get rid of this problem once and forever.
MailPoet sets the database port number in a class Env (file
/mailpoet/lib/config/Env.php
). You do that by getting the port number from the DB_HOST constant setting in the wp-config.php file and, if it is not defined there, using a default value of 3306.All problems come down to the fact that sometimes the assumption “if not specified, we should use 3306” does not apply. Therefore I think it would be better not to use the data specified in wp-config.php, but to get the port number from the database itself, just like you get the user-defined table name prefix from the database itself.
I tried to do this by replacing line 86 in
/mailpoet/lib/config/Env.php
, saying:
self::$dbPort = $port ?: 3306;
by the following:
self::$dbPort = $wpdb->get_results("SELECT @@port", ARRAY_N)[0][0];
That works. No need to specify the right port number yourself, no troubles porting the site to a different web server using a different port numbering strategy.
Of course you guys know your software endlessly much better then I do, and I may very well be overlooking something or this might create problems elsewhere in the software, but I thought I should let you know, for your kind consideration.
Best regards,
Henk
- The topic ‘No more database port number problems?’ is closed to new replies.