cabrerahector / wordpress-popular-posts

WordPress Popular Posts - A highly customizable WordPress widget that displays your most popular posts.
https://wordpress.org/plugins/wordpress-popular-posts/
GNU General Public License v2.0
280 stars 82 forks source link

mysqli::real_connect() expects parameter 5 to be integer, string given #240

Closed gormus closed 4 years ago

gormus commented 4 years ago

Describe the bug My log is filled with so many messages like this, and all seems to be pointing to WPP plugin:

{
  "message": "mysqli::real_connect() expects parameter 5 to be integer, string given",
  "context": {
    "query": "SELECT p.ID AS id, p.post_title AS title, p.post_author AS uid, p.post_date AS date, v.pageviews FROM `wp_posts` p INNER JOIN (SELECT SUM(pageviews) AS pageviews, postid FROM `wp_popularpostssummary` WHERE view_datetime > DATE_SUB('2019-12-16 01: 00: 08', INTERVAL 60 DAY) GROUP BY postid) v ON p.ID = v.postid WHERE 1 = 1 AND p.post_type IN('post') AND p.post_password = '' AND p.post_status = 'publish'  ORDER BY pageviews DESC LIMIT 6 OFFSET 0;",
    "file": "/web/wp-includes/wp-db.php",
    "line": 2030
  },
  "level": 300,
  "level_name": "WARNING",
  "channel": "PHP-ERROR",
  "extra": {
    "wp": {
      "doing_cron": false,
      "doing_ajax": false,
      "is_admin": false,
      "doing_rest": false,
      "user_id": 0
    }
  },
  "@timestamp": "2019-12-16T00: 00: 11+00: 00"
}

Expected behavior No errors to log for.

Environment:

Additional context Due to support has been dropped for qTranslate-XT, we have to use WPP < 5.0 for the time being.

In my experience, this error message often refers to database port if it's defined as a string, in the db connection strings. However, this is puzzling, since WordPress doesn't even have a constant for the db port, or it's defined anywhere.

cabrerahector commented 4 years ago

Hi @gormus,

I'm as puzzled as you but I believe this is a WordPress issue, nothing to do with WPP.

In my experience, this error message often refers to database port if it's defined as a string, in the db connection strings. However, this is puzzling, since WordPress doesn't even have a constant for the db port, or it's defined anywhere.

According to the documentation, you can specify the port number via the DB_HOST constant:

If your host uses an alternate port number for your database you’ll need to change the DB_HOST value in the wp-config.php file to reflect the alternate port provided by your host.

Eg. define( 'DB_HOST', 'localhost:3307' );

WordPress then will attempt to extract the port number from that string (if present) and pass it to the mysqli_real_connect() function (see related code here) without explicitly converting it into an integer first which might be the reason why mysqli_real_connect() is complaining.

Assuming you didn't configure a port number in your DB_HOST constant, try setting it up and see if it helps. Other than that I'm honestly out of ideas.

gormus commented 4 years ago

Thank you for your prompt response @cabrerahector!

I was hesitant, and I was going to try what you suggested in your reply as a backup plan; I guess I was hoping you might have an alternative solution.

Much appreciated though. I'll keep posted with my findings.

gormus commented 4 years ago

Hi @cabrerahector and anyone who experiences the same issue,

Setting the database host and the port together completely resolved the issue for me. No more errors.

define( 'DB_HOST', 'localhost:3306' );

cabrerahector commented 4 years ago

Due to support has been dropped for qTranslate-XT, we have to use WPP < 5.0 for the time being.

Thought I should let you know, Osman: https://wordpress.org/support/topic/translation-fails-since-last-update/#post-12274242

gormus commented 4 years ago

@cabrerahector I only recently had a chance to upgrade the WPP to latest. Works flawlessly with qTranslate-XT. Thanks Hector!