PHP to D Conversion

Vino akashvino79 at gmail.com
Fri Oct 18 06:22:33 UTC 2019


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


More information about the Digitalmars-d-learn mailing list