Skip to content

No issue, but a correction for lib/database.php to take in consideration DB port number #8

@Ficoba

Description

@Ficoba

Hello,

I helped a coworker to install your plugin.
And we have detected an issue for DB connection.
For information after plugin installation all pages showed:

SQLSTATE[HY000] [2002]

In fact in our company we have dedicated DB servers and we use different ports depending on the project.

In your project the lib/database.php file does not take in consideration the $database_port of Cacti configuration.

Below you will find a correction:

<?php

/**
 * @return null|PDO
 */
function weathermap_get_pdo()
{
    // This is the Cacti standard settings
    global $database_type, $database_default, $database_hostname, $database_port, $database_username, $database_password;
    global $config;

    $cacti_version = $config["cacti_version"];

    $host = $database_hostname;
    $dbname = $database_default;
    $user = $database_username;
    $pass = $database_password;
    $port = $database_port;

    $pdo = null;

    try {
        # MySQL with PDO_MYSQL
        $pdo = new \PDO("mysql:host=$host;port=$port;dbname=$dbname", $user, $pass);
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    } catch (PDOException $e) {
        echo $e->getMessage();
    }

    return $pdo;
}

We have just added:

  • Line 9: $database_port
  • Line 18: $port = $database_port;
  • Line 24 (old 23): ;port=$port

Regards,
Ficoba

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already existsresolvedA resolved issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions