October 21, 2019 Re: PHP to D Conversion | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vino | On Monday, 21 October 2019 at 11:36:00 UTC, Vino wrote:
> On Saturday, 19 October 2019 at 20:40:36 UTC, Boris Carvajal wrote:
>> [...]
>
> Hi Boris,
>
> [...]
Hi,
Where do you call avmconnect?
Is this.conn null when connection fails?
What happens if the query does not contains rows?
Kind regards
Andre
|
October 21, 2019 Re: PHP to D Conversion | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vino | On Friday, 18 October 2019 at 06:22:33 UTC, Vino wrote: > Hi All, > > Request your help in converting a PHP code to D equivalent code > > PHP Code: > class avmtest { > private $con; > > function __construct() { > global $config; > $this->con = new mysqli(test.srv.com:3910, testusr, xxxx#, test); > if($this->con->connect_errno) { die("Connection Failed.\n"); } > } > > function getHostname() { > $qdata = $this->con->prepare("SELECT host_name FROM hosts_coll"); > $qdata->execute(); > $qdata->bind_result($host); > while($qdata->fetch()) { > $data[] = array("HostName" => $host); > } > $sdata->close(); > return $data; > } > } > > D Code: > module avm.test; > > import mysql; > import std.array : array; > import std.conv; > import std.variant; > > class avmtest > { > private conn; > > auto avmconnect() > { > auto connectionStr = "host=test.srv.com;port=3910;user=testusr;pwd=xxxx#;db=test"; > Connection conn = new Connection(connectionStr); > scope(exit) conn.close(); > } > > auto getHostname() > { > ResultRange qdata = conn.query("SELECT host_name FROM `hosts_coll`"); > Row row = qdata.front; > Variant h = row[0]; > qdata.close(); > return h.to!string; > } > } > > Error: Error: no identifier for declarator conn > > From, > Vino.B import hunt.database; class avmtest { private Database db; this() { db = new Database("mysql://testusr:xxxx@test.srv.com:3910/test"); } string[string][] getHostname() { string[string] data; foreach(row; db.query("SELECT host_name FROM hosts_coll")) { string[string] host; host["HostName"] = row["host_name"]; data ~= host; } return data; } } |
October 21, 2019 Re: PHP to D Conversion | ||||
---|---|---|---|---|
| ||||
Posted in reply to zoujiaqing | On Monday, 21 October 2019 at 15:29:33 UTC, zoujiaqing wrote:
> On Friday, 18 October 2019 at 06:22:33 UTC, Vino wrote:
>> [...]
>
>
> import hunt.database;
>
> class avmtest {
>
> private Database db;
>
> this() {
> db = new Database("mysql://testusr:xxxx@test.srv.com:3910/test");
> }
>
> string[string][] getHostname() {
>
> string[string] data;
>
>
> foreach(row; db.query("SELECT host_name FROM hosts_coll"))
> {
> string[string] host;
> host["HostName"] = row["host_name"];
> data ~= host;
> }
>
> return data;
> }
> }
Is this database library compatible with the fiber programming model of vibe-d?
Kind regards
Andre
|
October 22, 2019 Re: PHP to D Conversion | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre Pany | On Monday, 21 October 2019 at 15:36:25 UTC, Andre Pany wrote:
> On Monday, 21 October 2019 at 15:29:33 UTC, zoujiaqing wrote:
>> On Friday, 18 October 2019 at 06:22:33 UTC, Vino wrote:
>>> [...]
>>
>>
>> import hunt.database;
>>
>> class avmtest {
>>
>> private Database db;
>>
>> this() {
>> db = new Database("mysql://testusr:xxxx@test.srv.com:3910/test");
>> }
>>
>> string[string][] getHostname() {
>>
>> string[string] data;
>>
>>
>> foreach(row; db.query("SELECT host_name FROM hosts_coll"))
>> {
>> string[string] host;
>> host["HostName"] = row["host_name"];
>> data ~= host;
>> }
>>
>> return data;
>> }
>> }
>
> Is this database library compatible with the fiber programming model of vibe-d?
>
> Kind regards
> Andre
Yes.
There are no conflicts.
|
October 22, 2019 Re: PHP to D Conversion | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vino | On Friday, 18 October 2019 at 06:22:33 UTC, Vino wrote: > Hi All, > > Request your help in converting a PHP code to D equivalent code > You can get one connection object and close it :) ```D import hunt.database; class AvmTest { private Database _db; this() { _db = new Database("mysql://testusr:xxxx@test.srv.com:3910/test"); } string[string][] getHostname() { string[string][] data; auto conn = _db.getConnection(); foreach(row; conn.query("SELECT host_name FROM hosts_coll")) { string[string] host; host["HostName"] = row["host_name"]; data ~= host; } conn.close(); return data; } } ``` |
Copyright © 1999-2021 by the D Language Foundation