mysql-native Help required
Steven Schveighoffer
schveiguy at gmail.com
Thu Oct 22 14:08:30 UTC 2020
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
More information about the Digitalmars-d-learn
mailing list