digitalmars.D.learn - PHP to D Conversion
- Vino (54/54) Oct 17 2019 Hi All,
- Jacob Carlborg (7/60) Oct 18 2019 The instance variable in the D code, `conn`, doesn't have a
- Vino (10/18) Oct 18 2019 Hi Jacob,
- Vino (18/39) Oct 18 2019 App.d
- Vino (2/21) Oct 18 2019 And now getting the error : Program exited with code -1073741819
- Andre Pany (7/34) Oct 18 2019 Hi,
- Vino (6/18) Oct 19 2019 Hi Andre,
- Boris Carvajal (6/27) Oct 19 2019 Your program is crashing probably because you are dereferencing a
- Vino (49/79) Oct 21 2019 Hi Boris,
- Andre Pany (7/12) Oct 21 2019 Hi,
- Aldo (5/16) Oct 18 2019 You are using a new connection here, maybe you want to use
- zoujiaqing (21/76) Oct 21 2019 import hunt.database;
- Andre Pany (5/27) Oct 21 2019 Is this database library compatible with the fiber programming
- zoujiaqing (3/38) Oct 21 2019 Yes.
- zoujiaqing (25/28) Oct 21 2019 You can get one connection object and close it :)
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, 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 = 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
Oct 17 2019
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, 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 = 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 connThe instance variable in the D code, `conn`, doesn't have a type. I guess the type should be `Connection`. In the D version of `avmconnect` you're declaring a local variable named `conn` instead of referring to the instance variable. -- /Jacob Carlborg
Oct 18 2019
On Friday, 18 October 2019 at 08:54:40 UTC, Jacob Carlborg wrote:On Friday, 18 October 2019 at 06:22:33 UTC, Vino wrote:Hi Jacob, Thank you, I have made the below changes, and rebuilt the application, now the application complied without any error, but when i try to access the URL from webpage it errors out with "127.0.0.1 refused to connect" private Connection conn; //added scope(exit) conn.close(); //removed From, Vino.B[...]The instance variable in the D code, `conn`, doesn't have a type. I guess the type should be `Connection`. In the D version of `avmconnect` you're declaring a local variable named `conn` instead of referring to the instance variable. -- /Jacob Carlborg
Oct 18 2019
On Friday, 18 October 2019 at 09:11:18 UTC, Vino wrote:On Friday, 18 October 2019 at 08:54:40 UTC, Jacob Carlborg wrote:App.d import vibe.vibe; import avm.test; void main() { auto settings = new HTTPServerSettings; settings.port = 8080; settings.bindAddresses = ["127.0.0.1"]; listenHTTP(settings, &hello); logInfo("Please open http://127.0.0.1:8080/ in your browser."); runApplication(); } void hello(HTTPServerRequest req, HTTPServerResponse res) { test t = new avmtest(); res.writeBody(t.getHostname); }On Friday, 18 October 2019 at 06:22:33 UTC, Vino wrote:Hi Jacob, Thank you, I have made the below changes, and rebuilt the application, now the application complied without any error, but when i try to access the URL from webpage it errors out with "127.0.0.1 refused to connect" private Connection conn; //added scope(exit) conn.close(); //removed From, Vino.B[...]The instance variable in the D code, `conn`, doesn't have a type. I guess the type should be `Connection`. In the D version of `avmconnect` you're declaring a local variable named `conn` instead of referring to the instance variable. -- /Jacob Carlborg
Oct 18 2019
On Friday, 18 October 2019 at 09:17:24 UTC, Vino wrote:On Friday, 18 October 2019 at 09:11:18 UTC, Vino wrote:And now getting the error : Program exited with code -1073741819[...]App.d import vibe.vibe; import avm.test; void main() { auto settings = new HTTPServerSettings; settings.port = 8080; settings.bindAddresses = ["127.0.0.1"]; listenHTTP(settings, &hello); logInfo("Please open http://127.0.0.1:8080/ in your browser."); runApplication(); } void hello(HTTPServerRequest req, HTTPServerResponse res) { test t = new avmtest(); res.writeBody(t.getHostname); }
Oct 18 2019
On Friday, 18 October 2019 at 09:21:46 UTC, Vino wrote:On Friday, 18 October 2019 at 09:17:24 UTC, Vino wrote:Hi, Maybe port 8080 is blocked, because there is an instance of your application running on the background. Just check by changing the port in the source code. Kind regards AndreOn Friday, 18 October 2019 at 09:11:18 UTC, Vino wrote:And now getting the error : Program exited with code -1073741819[...]App.d import vibe.vibe; import avm.test; void main() { auto settings = new HTTPServerSettings; settings.port = 8080; settings.bindAddresses = ["127.0.0.1"]; listenHTTP(settings, &hello); logInfo("Please open http://127.0.0.1:8080/ in your browser."); runApplication(); } void hello(HTTPServerRequest req, HTTPServerResponse res) { test t = new avmtest(); res.writeBody(t.getHostname); }
Oct 18 2019
On Friday, 18 October 2019 at 14:56:05 UTC, Andre Pany wrote:On Friday, 18 October 2019 at 09:21:46 UTC, Vino wrote:Hi Andre, Tried with different ports still no luck getting this error : Program exited with code -1073741819. From, Vino.BOn Friday, 18 October 2019 at 09:17:24 UTC, Vino wrote:Hi, Maybe port 8080 is blocked, because there is an instance of your application running on the background. Just check by changing the port in the source code. Kind regards Andre[...]And now getting the error : Program exited with code -1073741819
Oct 19 2019
On Saturday, 19 October 2019 at 19:08:45 UTC, Vino wrote:On Friday, 18 October 2019 at 14:56:05 UTC, Andre Pany wrote:Your program is crashing probably because you are dereferencing a null/ dangling pointer. Build your program in debug mode and run it in a debugger, that way you will get a backtrace telling you the exactly line of the code when it happens.On Friday, 18 October 2019 at 09:21:46 UTC, Vino wrote:Hi Andre, Tried with different ports still no luck getting this error : Program exited with code -1073741819. From, Vino.BOn Friday, 18 October 2019 at 09:17:24 UTC, Vino wrote:Hi, Maybe port 8080 is blocked, because there is an instance of your application running on the background. Just check by changing the port in the source code. Kind regards Andre[...]And now getting the error : Program exited with code -1073741819
Oct 19 2019
On Saturday, 19 October 2019 at 20:40:36 UTC, Boris Carvajal wrote:On Saturday, 19 October 2019 at 19:08:45 UTC, Vino wrote:Hi Boris, I tired to build the code in debug mode and ran the program in debugger , the debugger is complaining about the line "this.conn = new Connection(connectionStr);", not sure what is wrong in the below code, hence request your help. Have the checked the connection string and the info is correct. import vibe.vibe; import mysql; import std.array : array; import std.conv; import std.variant; class avmtest { private Connection conn; auto avmconnect() { auto connectionStr = this.conn = new Connection(connectionStr); } 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; } } void hello(HTTPServerRequest req, HTTPServerResponse res) { auto t = new avmtest(); res.writeBody(t.getHostname); } void main() { auto settings = new HTTPServerSettings; settings.port = 8130; settings.bindAddresses = ["127.0.0.1"]; listenHTTP(settings, &hello); logInfo("Please open http://127.0.0.1:8130/ in your browser."); runApplication(); } From, Vino.BOn Friday, 18 October 2019 at 14:56:05 UTC, Andre Pany wrote:Your program is crashing probably because you are dereferencing a null/ dangling pointer. Build your program in debug mode and run it in a debugger, that way you will get a backtrace telling you the exactly line of the code when it happens.On Friday, 18 October 2019 at 09:21:46 UTC, Vino wrote:Hi Andre, Tried with different ports still no luck getting this error : Program exited with code -1073741819. From, Vino.BOn Friday, 18 October 2019 at 09:17:24 UTC, Vino wrote:Hi, Maybe port 8080 is blocked, because there is an instance of your application running on the background. Just check by changing the port in the source code. Kind regards Andre[...]And now getting the error : Program exited with code -1073741819
Oct 21 2019
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, Where do you call avmconnect? Is this.conn null when connection fails? What happens if the query does not contains rows? Kind regards Andre[...]Hi Boris, [...]
Oct 21 2019
On Friday, 18 October 2019 at 06:22:33 UTC, Vino wrote:class avmtest { private conn;You need to specify the type of conn. private Connection conn;auto avmconnect() { auto connectionStr = Connection conn = new Connection(connectionStr); scope(exit) conn.close(); }You are using a new connection here, maybe you want to use this->conn instead of Connection conn; By the way you are closing it everytime with scope(exit).
Oct 18 2019
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, 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 = 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.Bimport 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; } }
Oct 21 2019
On Monday, 21 October 2019 at 15:29:33 UTC, zoujiaqing wrote:On Friday, 18 October 2019 at 06:22:33 UTC, Vino wrote:Is this database library compatible with the fiber programming model of vibe-d? Kind regards Andre[...]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; } }
Oct 21 2019
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:Yes. There are no conflicts.On Friday, 18 October 2019 at 06:22:33 UTC, Vino wrote:Is this database library compatible with the fiber programming model of vibe-d? Kind regards Andre[...]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; } }
Oct 21 2019
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 codeYou 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; } } ```
Oct 21 2019