0

Here's the example function:

#pragma once

#include <string>
#include <iostream>
#include <pqxx/pqxx>

int main()
{
    std::string connectionString = "host=ec2-54-74-35-87.eu-west-1.compute.amazonaws.com port=5432 dbname=d8iolcesns1bj4 user=pktunepcutgdqh password=7e3eeef2e01e0d8ae555c7236b1c3375789259dfb6acba41225cc4f55394836c";

    try
    {
        pqxx::connection connectionObject(connectionString.c_str());

        pqxx::work worker(connectionObject);

        pqxx::result response = worker.exec("SELECT * FROM Users");

        for (size_t i = 0; i < response.size(); i++)
        {
            std::cout << "Id: " << response[i][0] << " Username: " << response[i][1] << " Password: " << response[i][2] << std::endl;
        }
    }
    catch (const std::exception& e)
    {
        std::cerr << e.what() << std::endl;
    }

    system("pause");
}

And I would like to create a class which would hold the data about the connection, like this:

#pragma once
#include <string>
#include <pqxx/pqxx>

class DBLink
{
    std::string connectionString = "host=ec2-54-74-35-87.eu-west-1.compute.amazonaws.com port=5432 dbname=d8iolcesns1bj4 user=pktunepcutgdqh password=7e3eeef2e01e0d8ae555c7236b1c3375789259dfb6acba41225cc4f55394836c";
    pqxx::connection connectionObject(connectionString.c_str());
    pqxx::work worker(connectionObject);
};

but for some reason I get some errors: photo

is there any way to fix them?

Octavian Niculescu
  • 1,177
  • 1
  • 3
  • 24

0 Answers0