On 10/22/20 7:04 AM, Vino wrote:
Hi All,


   Request your help on the below code as it is not working as expected.

GetConnections.d

module common.GetConnections;
import mysql;

class Connections
{
   private Connection conn;
  auto constr = "host=localhost;port=3910;user=user;pwd=password#;db=testdb";

I'd declare this immutable, so it's not stored in the class:

immutable constr = "...";

   this.conn = new Connection(constr);

You are trying to assign an instance member at compile time, with no actual instance.

You need a constructor

     this() { this.conn = new Connection(constr); }
}

GetHost.d

import common.GetConnections;
import std.array : array;
import std.variant;
import mysql;
import std.stdio: writeln;

void main()
{
  auto conn = new Connections();
  Row[] data = conn.query("SELECT * FROM hostlog").array;
  writeln(data[]);
}

The rest should work.

-Steve

Reply via email to